-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Try state in context with useHook #7
base: master
Are you sure you want to change the base?
Conversation
@RonanFelipe This is an alternative implementation that is not hacking into the And it is using |
Hi @the-funnel You have 9 comments made by bots installed on this repo regarding this pull request. Check them below: There are 7 critical comments
There is 1 deploy comment
There is 1 info comment
|
Resolves: #6
Benefits
Goals
Is there anything we need to do to enable this feature for components?
Yes
The PR introduces two new hooks:
useStateContextConsumer
anduseStateContextProvider
. To create a context you can use the helper functioncreateStateContext
.useStateContextProvider
This hook should be used by the parent component. For example
ComboboxPopover
is a component that containsComboboxOption
. In this case,ComboboxPopover
is the parent component and it should provide the context.First, you will need a context:
Then you need to add the hook to the
compose
array as the very first value:If your component is using
useComposeProps
too, then you need to add the hook there as well:useStateContextConsumer
This hook should be used by the child component. For example
ComboboxPopover
is a component that containsComboboxOption
. In this case,ComboboxOption
is the child component and it should consume the context.You should create a context in your parent component as mentioned above. Then you need to add the hook to the
compose
array as the very first value:useStateContextConsumer
takes an object with 3 properties:context
the context that you would like to consume, this should be the context that your parent component providesshouldUpdate
a function that returns whether the component should update its state or not. This function gives you 3 parameters:id
of the component,state
current state of the component andnextState
which is the state that we just received from the context. If we returntrue
, then thenextState
will be applied to the component.updateDependencies
under the hood, the pubsub system takes some dependencies. According to these dependencies, your component resubscribes to the pubsub system. This makes sure you receive correct values inshouldUpdate
.How to test?
npm run storybook
Combobox -> Combobox Non Context Vs Context
Does this PR introduce breaking changes?
Hopefully not!