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

useContext hook with IntlContext returns new reference every time issue #63

Open
wants to merge 1 commit into
base: preactX
Choose a base branch
from

Conversation

sitaram-mulik-synacor
Copy link

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.

Slackblitz link where the issue is reproducible:
https://stackblitz.com/edit/preact-starter-template-6lb3ag?file=index.js

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

Successfully merging this pull request may close these issues.

1 participant