Skip to content

Added new React 18 hook useId and tests#14044

Merged
guidari merged 3 commits into
carbon-design-system:mainfrom
guidari:11513-react-useid
Jun 23, 2023
Merged

Added new React 18 hook useId and tests#14044
guidari merged 3 commits into
carbon-design-system:mainfrom
guidari:11513-react-useid

Conversation

@guidari

@guidari guidari commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

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

  • Added useId from React 18
  • Added tests for the useFallbackId hook

Changed

  • Changed the useId.server-test.js test. With this new useId hook 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:

  • Change the React version to an older version (17, 16...) in the package.json
  • Restart the server by running npm install and npm run dev

In 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 useId hook

Screenshot 2023-06-20 at 17 10 04

@guidari guidari requested a review from a team as a code owner June 20, 2023 20:13
@netlify

netlify Bot commented Jun 20, 2023

Copy link
Copy Markdown

Deploy Preview for carbon-components-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 33e505b
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/6495e2a997d4c80008509eed
😎 Deploy Preview https://deploy-preview-14044--carbon-components-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify

netlify Bot commented Jun 20, 2023

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 33e505b
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/6495e2a9297ce1000896e355
😎 Deploy Preview https://deploy-preview-14044--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@guidari guidari added type: infrastructure 🤖 Issues relating to devops, tech debt, etc. type: enhancement 💡 and removed type: infrastructure 🤖 Issues relating to devops, tech debt, etc. labels Jun 21, 2023

@tay1orjones tay1orjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@tw15egan tw15egan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome
LGTM 👍 ✅

@guidari guidari enabled auto-merge (squash) June 23, 2023 18:13
@guidari guidari merged commit af94b4f into carbon-design-system:main Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React 18 Enhancements: Update useId usage to use new hook available in React 18

3 participants