Added new React 18 hook useId and tests#14044
Merged
Merged
Conversation
✅ Deploy Preview for carbon-components-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
tay1orjones
approved these changes
Jun 23, 2023
tay1orjones
left a comment
Member
There was a problem hiding this comment.
This looks great, thanks for updating the server test as well!
I can't think of any ways that this could impact consumers already using React 18. The format of the id will change slightly, but tests etc. shouldn't be being written against hardcoded Ids generated from this useId().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11513
It was added the new hook in React 18 called
useId. This hook will take of hydration for us now.We are checking if the user is running a compatible version and calling the function
nativeReactUseId, otherwise we will keep using our old logic.Changelog
New
useIdfrom React 18useFallbackIdhookChanged
useId.server-test.jstest. With this newuseIdhook an id will be genarate in the server also.Testing / Reviewing
To test the code you have to switch between React versions.
I created a Stackblitz where you can test that by following these steps:
package.jsonnpm installandnpm run devIn the right panel you should see the changes.
To check in the Storybook you can go to the Accordion component and check if it has an id populate with the
useIdhook