-
Notifications
You must be signed in to change notification settings - Fork 109
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
Hookstate error 111 doesn't exist #332
Comments
yes, it is v4 exception. It means you are switching a state source on rerender, ie. the initial value to useHookstate points to a different State on rerender. |
Is there a way to turn this off or bypass it somehow? It's causing hot module replacement in vite.js to fail. |
hmm... "It's causing hot module replacement in vite.js to fail." this should not be the cause... but when it throws this exception, what property do you acccess? what type is it? what object type is it? |
I don't even need to access anything. When vite tries to perform hmr after detecting changes in my code, the app crashes and this error is shown in the console. But then if i make another code change, hmr works. |
could you please create a reproducer repo? what state value do you provide to hookstate? |
https://github.com/ayodeji-jackson/vendre I have two global states using hookstate. both are arrays. |
thanks. I will have a look later in the evening. It looks like Vite reloads globals but does not reload React state behind useState, which is clearly a problem, which makes useState bug-prone under hot reload in Vite. You basically end up with one state behind a global variable and another one captured in component state on the previous rerender. This makes the globals leaking under hmr in vite. I do not think this is the issue with react-scripts, but I will double check. I am not sure what to do to fix it: removing the exception is possible but the problems will appear later in the app, leaving exception is a problem for vite... |
oh yeah. keeping previous state on component re-render is one of vite's features. do you think using hookstate for all local states will fix it? or i could check if disabling this feature is an option. |
local state is not impacted.. it is a global one i think... please let me know if it can be tuned... |
When setting your states, use arrow function to prevent this error, like; const test = hookstate(null); export function useTestState() { hope this helps. |
Having the same issues in Next.js v13.0.5. Getting
Any other ways to get around this? 🙏🏻 |
If error is gone after using arrow function, check your code again, because if that was the reason you are getting 111 error it means your state was updating one step behind. You maybe adapted this, structured your code and now your code doesnt work it used to be :) I am talking blindly of course, maybe some code snippets? |
Yeah, sorry, should have posted a snippet. Here goes:
In this example above I get the 111 error on hmr, but the code works apart from that. If I do |
Try to seperate your states and import them and you wont get this error and your hooks will work as you wanted. I think the cause of the problem is strict mode. Or a better solution will be using useHookstateMemo function useGlobalState(){ and you can use it in your component like; const todos = useGlobalState(); |
@avkonst you should close some of the issues, I really like hookstate but its getting harder to convince people to use this awesome tool. :) |
this is now part of the docs: https://hookstate.js.org/docs/exceptions/#hookstate-111 |
@HidayetCanOzcan sure... I am just overloaded with stuff. 60+ hours per week at work. And it is Summer time where I live. But I will clean it up soon. |
The error 111 is not part of the docs yet, but I will update soon |
Oops saw 101 and read 111 😅 |
Just wanna confirm that this worked for me! Thanks a lot!
|
No problem, glad to help :) |
see related follow up #364 |
docs updated |
My application has thrown a hookstate error 111 with the link https://hookstate.js.org/docs/exceptions/#hookstate-111. This does not exist in the documentation.
The text was updated successfully, but these errors were encountered: