-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: Use useStoreState()
instead of store.useState()
#64648
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
if ( ! context ) { | ||
warning( '`Tabs.TabPanel` must be wrapped in a `Tabs` component.' ); | ||
return null; | ||
} | ||
const { store, instanceId } = context; | ||
const instancedTabId = `${ instanceId }-${ tabId }`; | ||
const selectedId = store.useState( ( state ) => state.selectedId ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved up above the condition to fulfill the rules of hooks. Simplified the callback syntax.
@@ -359,10 +361,11 @@ export default function ViewList< Item >( props: ViewListProps< Item > ) { | |||
|
|||
const store = useCompositeStore( { | |||
defaultActiveId: getItemDomId( selectedItem ), | |||
} ); | |||
} ) as CompositeStore; // TODO, remove once composite APIs are public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary for the useStoreState
call. Previously was any
due to the locked nature of the private API.
@@ -3,6 +3,8 @@ | |||
*/ | |||
import clsx from 'clsx'; | |||
// TODO: use the @wordpress/components one once public | |||
// eslint-disable-next-line no-restricted-imports | |||
import { useStoreState } from '@ariakit/react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WordPress/gutenberg-components WDYT - should we re-export this from @wordpress/components
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends on what we decide around exposing stores in #63704. Better hold off for now
Flaky tests detected in 13619bd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10474021732
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smok tested with Storybook, and everything seems to be in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few suggestions to clean up Tabs
code, but otherwise code changes LGTM
Co-authored-by: ciampo <[email protected]>
…Press#64648) * Components: Use useStoreState() instead of store.useState() * CHANGELOG * Cleanup TabList Co-authored-by: ciampo <[email protected]> --------- Co-authored-by: ciampo <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: ciampo <[email protected]>
Resolves React Compiler issues. See WordPress/gutenberg#64648.
@@ -2,6 +2,7 @@ | |||
* External dependencies | |||
*/ | |||
import * as Ariakit from '@ariakit/react'; | |||
import { useStoreState } from '@ariakit/react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for using a separate import instead of Ariakit.useStoreState
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, no. I think it was caused by the automated way I addressed these changes. Let me fix these in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What?
After updating to Ariakit
v0.4.10
, we're changingstore.useState()
instances to the newuseStoreState()
API.Why?
To resolve problems with the React Compiler raising errors when using
store.useState()
:See #61788.
How?
We're updating the syntax.
For instances that were conditionally called, we're moving them above the condition as needed.
Testing Instructions
Testing Instructions for Keyboard
None
Screenshots or screencast
None