-
Notifications
You must be signed in to change notification settings - Fork 2
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(toast): Fix unnecessarily re-rendering all children of toast context on every state change #197
Conversation
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]>
…ry re-rendering children
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.
This approach is the way to go when using Contexts 🥇 I had a few comments about how we can make the consumers safer
By the way, we can update the file structure here. We recently started using this convention on Tinyman and it looks quite nice:
|
I think it's a good idea to make these files more organized 👍 I'll create an issue, we can do this refactor in another PR, also for |
What is the problem?
dispatch
function. But in the current implementation, sinceuseToaster
returns both state and dispatch in the same object, dispatch function will "change" on every state change, and this will cause re-render in the components that usedispatch
.Possible (implemented) Solution
dispatch
Result (before vs after) [green border means that element is re-rendered]
I tried on my local with
npm-link
, here is the result:https://user-images.githubusercontent.com/22727931/175345592-35eadfd1-6b05-4a3d-9334-7320a0e95f32.mov
Only necessary elements re-renders. As expected.
If the app is only using
useToaster
, it won't be a breaking change and won't require any changes on the project