-
Notifications
You must be signed in to change notification settings - Fork 467
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
Infinite re-rendering with hook #285
Comments
Hey @dawsonc623 Please do not use those "hooks" - the implementation is broken and should be revisited. Here's a discussion regarding possible implementation |
Hello @krizzu Thanks for the reply. I will avoid the hook for now and use the standard API. Do you know when the hook might be looked at again? |
Haven't thought about specific date, but definitely should land in v2! |
Wouldn't wrapping the functions with getItem: useCallback((...args) => AsyncStorage.getItem(key, ...args), [key]),
setItem: useCallback((...args) => AsyncStorage.setItem(key, ...args), [key]),
mergeItem: useCallback((...args) => AsyncStorage.mergeItem(key, ...args), [key]),
removeItem: useCallback((...args) => AsyncStorage.removeItem(key, ...args), [key]), |
In my opinion, the hook here is to paint the lily. |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
Not stale. |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
Not stale. |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
Not stale. |
Not stale. |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
Not stale (but will likely never be solved too). |
Still not stale.... Is this going to be addressed? Is there another library I can use? |
It will be fixed when PR #760 is merged |
This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed. |
It's the work done by @pke the way you guys want to procced?. I am hitting this error as well, i might try to help with that. Any more insights, context on the issue? It would be my first issue on the project but i am hitting that without using the hook. |
Current behavior
I assume this behaviour is due to the functions coming back being new instances each time, but if I use the functions returned from the hook in a
useEffect
and add them to the dependency array, theuseEffect
fires infinitely. I can solve this by either not including them in the dependency array (not good practice) or wrapping them in auseCallback
(not extraordinarily elegant, but better than the first option).Expected behavior
The functions returned from the hook should be able to be placed in a dependency array of a useEffect without issue.
Repro steps
getItem
function (for example) from the hook.useEffect
hook that usesgetItem
.console.warn
).getItem
to the dependency array of theuseEffect
.Environment
The text was updated successfully, but these errors were encountered: