-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Component setState doesn't allow Symbol keys #6372
Comments
What is the use case for using Symbols as state keys? State is already private and is never shared so it’s not clear what the benefit of supporting Symbols as keys is. Would you mind sharing your thoughts on this? |
Sure, check out https://jsfiddle.net/gingur/4ury0beq/2/. The idea is a Symbol can be provided as a prop to map a "dynamic" state property. Now given, this could also be accomplished with unique strings but the use case at least is demonstrated. |
cc @sebmarkbage Basically this boils down to the fact that the react/src/renderers/shared/reconciler/ReactCompositeComponent.js Lines 762 to 771 in 22a3d03
|
@zpao if it was just the edit: Oh I see, it doesn't actually use the native |
No, it's a "polyfill" which we always use and never fall back to native implementation. This was because at the time of adding this, the |
So would you be open to a PR that checks for symbols as well in |
I don't know yet, would like to get input from @sebmarkbage about intent before deciding how to fix it (personally, I think if yes we would likely just get rid of our polyfill and use babel-polyfill/runtime for it or even just say that you must include a polyfill of your own like we have for ES5 code) |
Yea, we should use native if available. Either using our own module or a mandatory external polyfill. Probably best to keep our own if a native is not available. Easy to miss the polyfill warning if you're only testing in modern browsers. |
The |
So to be clear, is the purposed solution to eventually rely on the consumer to implement appropriate polyfill (ie https://github.com/zloirock/core-js/blob/v2.2.1/modules/_object-assign.js via |
Would be nice if there was a |
Worth noting that there are very few cases of these. We've long used ES5 but ES6 is mostly compiled out or we provide our own polyfills (Object.assign as a module, Object.is inlined are the only 2 I know of). The idea of a react-polyfill repo is interesting though and definitely something we'll keep in mind moving forward. |
https://jsfiddle.net/gingur/eqprn74c/
When trying to do something like
this.setState({ [someSymbol]: 'someValue' });
therender
is being invoked properly but thethis.state[someSymbol]
is undefined. RunningObject.getOwnPropertySymbols
onthis.state
I have confirmed thatthis.setState
does not define Symbol properties.The text was updated successfully, but these errors were encountered: