Skip to content
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

Still unstable value used in Provider #84

Open
pke opened this issue Sep 21, 2021 · 3 comments
Open

Still unstable value used in Provider #84

pke opened this issue Sep 21, 2021 · 3 comments

Comments

@pke
Copy link

pke commented Sep 21, 2021

Hey, I am still experience massive re-renders whenever a toast message is shown.
So I checked the value used in the Provider and its creating a new object hash on every render, which makes it unstable (for react).
As a side note, the structure of the value does not comply with the defined ToastContextType because only the toast method is ever exported in the object of value.

<ToastContext.Provider value={{ toast }}>

When I changed the value to really only export the toast function (which in itself is stable thanks to useCallback) the app became more stable instantly.

<Provider value={toast}>

I am not sure what the root cause of all that is, might be an even outer mounted component that causes this packages Provider to re-render and by that trigger some ripple effects in the app.

I am trying to come up with a proper test suite to find out more about this behaviour but maybe you also have an idea whats going on?

@pke
Copy link
Author

pke commented Oct 27, 2021

Would you accept a PR to fix that?
The signature for the ToastProvider props is also not correct. It should not be the same as the context. Those two are not related. Props are input, context is output.

I have a patch-file for all of those changes, if you want.

@jeanverster
Copy link
Owner

Hey @pke a PR would be great! Apologies for the lack of input from my side, I recently moved to another country and has been difficult to tend to my open source projects + new job.. But should have more time to address issues here going forward :) When submitting a pr, please make use of angular commit conventions so that the CI knows how to version the project accordingly. And the base branch needs to be set to develop - thanks!

@pke
Copy link
Author

pke commented Nov 6, 2021

Sure, Jean. I will see when I can alot some time to create a PR. All the best in your new job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants