reactjs - What are the valid symbols for a React 'key' -


what valid symbols react key prop such;

<div key="can use spaces example?"></div> 

in case want use url key

const links = [     {         label: 'foo label',         href: 'https://example.com',     },     {         label: 'bar label',         href: 'https://example.com',     } ]  links.map(     link => (<a key={link.href} href={link.href}>{link.label}</a>) ); 

is valid? thinking use hash function pass href through first, pointless step if character guaranteed valid in key value.

the reason i'm asking can't find example in doc uses non-alpha-numeric character key, , explicitly says that, if don't have id use key object you're rendering can hash part of make key. although because shouldn't use long keys, , should therefor hash content first truncate it's size, seems whole documentation implicitly says alpha-numeric characters should used key.

requirements react's key best described in documentation reconciliation

in practice, finding key not hard. of time, element going display has unique id. when that's not case, can add new id property model or hash parts of content generate key. remember key has unique among siblings, not globally unique.

so, key should unique (amongst siblings) , stable.

your example, therefore, fit. spaces should fine well.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -