Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why React change keys with dot dollar ? ".$" #22870

Closed
jonlepage opened this issue Dec 5, 2021 · 5 comments
Closed

Why React change keys with dot dollar ? ".$" #22870

jonlepage opened this issue Dec 5, 2021 · 5 comments
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion

Comments

@jonlepage
Copy link

Can we get explanation why all keys are mutate with .$ by react ?
image

so we always need a hack like this to extract key ?!

const { key, type, props } = childnode;
const keyid = ( key as string ).split( '.$' )[1];
@jonlepage jonlepage added React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion labels Dec 5, 2021
@bvaughn
Copy link
Contributor

bvaughn commented Dec 6, 2021

React does not set keys. Those come from your application code (or perhaps the 3rd party UI library that you're using). You can learn more about keys here: https://reactjs.org/docs/lists-and-keys.html#keys

@bvaughn bvaughn closed this as completed Dec 6, 2021
@jonlepage
Copy link
Author

jonlepage commented Dec 6, 2021

React does not set keys. Those come from your application code (or perhaps the 3rd party UI library that you're using). You can learn more about keys here: https://reactjs.org/docs/lists-and-keys.html#keys

Hum weird ! i trying a random codesandbox on web and open debug tools !
image

And it also seem have keys with .$
But the codesandbox seem not have thirdParty UI library !
https://codesandbox.io/s/react-keys-zrthc?from-embed

I'll try to investigate, but it's very weird !

@bvaughn
Copy link
Contributor

bvaughn commented Dec 6, 2021

But the codesandbox seem not have thirdParty UI library !

The "3rd party code" is the CSSTransitionGroupChild component, in this case, coming from react-addons-css-transition-group. This is a pretty old addon library (last published around 4 years ago) and I'm not sure how it works, but it's the thing generating/assigning keys.

@irinakk
Copy link
Contributor

irinakk commented Dec 6, 2021

This is the result of using React.Children.toArray or React.Children.map: #5541 (comment)

@jonlepage
Copy link
Author

jonlepage commented Dec 6, 2021

@irinakk Haaaa oki thanks a lot for your help ! i also using this on my side, so its maybe related !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion
Projects
None yet
Development

No branches or pull requests

3 participants