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

Called twice with react strict mode #10

Open
shadowvzs opened this issue Feb 21, 2023 · 3 comments
Open

Called twice with react strict mode #10

shadowvzs opened this issue Feb 21, 2023 · 3 comments

Comments

@shadowvzs
Copy link

Hi, in strict mode it is called twice, which is an issue if we have an api call method or class instantiation

@Andarist
Copy link
Owner

This is how React works - you can't instantiate anything that has side-effects with useConstant. Side effects belong to useEffect/event handlers (or to outside of your components)

@shadowvzs
Copy link
Author

@Andarist I thought it should be used for instantiating a store class too with useConstant but this isn't the case, useEffect is called after the component was mounted and not parallel

@Andarist
Copy link
Owner

Yes, but again - this is how React works. useConstant is resolved in render, and render should always be pure.

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