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
refactor(react): consolidate useControllableState to one hook #10255
refactor(react): consolidate useControllableState to one hook #10255
Conversation
✔️ Deploy Preview for carbon-react-next ready! 🔨 Explore the source changes: e3df732 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-react-next/deploys/61b283fd0f61470008a5935e 😎 Browse the preview: https://deploy-preview-10255--carbon-react-next.netlify.app |
✔️ Deploy Preview for carbon-elements ready! 🔨 Explore the source changes: e3df732 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-elements/deploys/61b283fd0f2a2500074078cc 😎 Browse the preview: https://deploy-preview-10255--carbon-elements.netlify.app |
✔️ Deploy Preview for carbon-components-react ready! 🔨 Explore the source changes: e3df732 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-components-react/deploys/61b283fd16f8e400086df89f 😎 Browse the preview: https://deploy-preview-10255--carbon-components-react.netlify.app |
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.
LGTM. Tests are passing and the components are working as expected. 👍🏽
warning( | ||
false, | ||
'A component is changing a controlled component to be uncontrolled. ' + | ||
'A component is changing a controlled %s component to be uncontrolled. ' + |
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 does %s
mean again?
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.
%s
is a convention used in warning
, it comes from sprintf
style formatters in languages like C. You can also do it in things like console.log()
, for example:
console.log('Hello, %s', 'world'); // 'Hello, world'
Basically it's a way of interpolating values into a string
*/ | ||
export function useControllableState({ | ||
defaultValue, | ||
name = 'custom', |
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.
Out of curiosity, what would an example of name
being used be? Would it be the name of the state being used or the component that is being controlled?
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.
@abbeyhrt great question, it'd be the latter. The idea with name
was that a component could provide the name
argument to offer better development error messages. So, for example, Tabs
could useControllableState({ name: 'Tabs' })
and it would say that "a Tabs component is switching from controlled to uncontrolled"
This PR consolidates our two versions of
useControllableState
into one hook:It also updates components that used the old form of this hook and updated import paths for components that used the new form.
Changelog
New
Changed
useControllabeState
hooks into one hookuseControllableState
Removed
Testing / Reviewing