react-native-styled-toast
react-native-styled-toast copied to clipboard
Still unstable value used in Provider
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
.
https://github.com/jeanverster/react-native-styled-toast/blob/010f2006eff14ab2abfab0c151828f7f1647c4af/src/Context/index.tsx#L78
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?
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.
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!
Sure, Jean. I will see when I can alot some time to create a PR. All the best in your new job!