-
-
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 use hook #40
base: master
Are you sure you want to change the base?
Conversation
…akit/reakit into try/state-in-context-use-hook
implement unit testred-experiment/packages/reakit/src/Composite/__utils/fillGroups.ts Lines 14 to 19 in dc33f3c
This comment was generated by todo based on a
|
define function's return typered-experiment/packages/reakit/src/Composite/__utils/findFirstEnabledItem.ts Lines 10 to 15 in dc33f3c
This comment was generated by todo based on a
|
implement unit test
This comment was generated by todo based on a
|
define this function return type
This comment was generated by todo based on a
|
@RonanFelipe This is an alternative implementation that is not hacking into the And it is using |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit dc33f3c:
|
@RonanFelipe Just finished this up 😄 Tests are passing. I'll experiment with other components as well. Would like to hear your thoughts about this implementation. |
Size Change: +1.15 kB (0%) Total Size: 258 kB
ℹ️ View Unchanged
|
Amazing work @EricRibeiro 🚀 I currently don't have time to review Reakit PRs (I work on react native right now and am currently trying to fight off burnout in these trying times, so avoiding out of hours projects) - I've removed myself from the review request - hope you don't mind! |
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
==========================================
- Coverage 95.12% 94.48% -0.64%
==========================================
Files 230 236 +6
Lines 3509 3592 +83
Branches 955 968 +13
==========================================
+ Hits 3338 3394 +56
- Misses 170 196 +26
- Partials 1 2 +1
Continue to review full report at Codecov.
|
Resolves: #39
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!