You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useContext hook with IntlContext creates an object with a new reference from the passed props every time it's called.
Problem:
If we use this hook directly or indirectly through any other hook inside a component which is getting iterated over a loop, results in performance issues due to unnecessary rendering.
Solution:
I think the ideal solution for this problem would be to replace the existing logic of the IntlProvider component (which uses local variables with new reference derived from the props passed) with a component state and pass it as context value. This way we can make use of useEffect hook for side effect logics like merging the properties of definition prop. Other approach could be to make use of useMemo hook, but that way we can not run separate logic based on different side effects.
useContext
hook withIntlContext
creates an object with a new reference from the passed props every time it's called.Problem:
If we use this hook directly or indirectly through any other hook inside a component which is getting iterated over a loop, results in performance issues due to unnecessary rendering.
Solution:
I think the ideal solution for this problem would be to replace the existing logic of the
IntlProvider
component (which uses local variables with new reference derived from the props passed) with a component state and pass it as context value. This way we can make use ofuseEffect
hook for side effect logics like merging the properties of definition prop. Other approach could be to make use ofuseMemo
hook, but that way we can not run separate logic based on different side effects.Slackblitz link where the issue is reproducible:
https://stackblitz.com/edit/preact-starter-template-6lb3ag?file=index.js
PR
#63
The text was updated successfully, but these errors were encountered: