-
Notifications
You must be signed in to change notification settings - Fork 55
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
useCache generate a new Map everytime it's ran #80
Comments
Hi @pocesar - there was a temporary regression with caching in It's worth noting that the caching issue you are seeing isn't related to the map itself. In fact, https://reactjs.org/docs/hooks-reference.html#useref
Here's in a example to demonstrate the performance of this library running on the latest version: https://yq1l6185ox.codesandbox.io/ Please make sure you are on the latest version and if you are still having any problems, post a comment here to let me know (preferably with a code example) and I'll be happy to re-open this issue. |
yeah, I'm using the latest version, but that's not what I meant. the "new Map()" is eagerly executed, and not lazily like in: const state = useState(() => {
return { some: 'initialState' }
})
const memoized = useMemo(() => {
return new Map()
}, []) the way code is created in this library seems to not deal with ref stability (for functions, objects, etc). this is a constructive criticism, that should focus on optimizations. spread props is already bad by itself and is the main drive of this hook. |
this part of the code https://github.com/wsmd/react-use-form-state/blob/master/src/useCache.js#L4
should be using
useMemo
instead with some mechanism for busting itself. this library already makes a lot of useless re-renders, it should start focusing on optimizing the codeThe text was updated successfully, but these errors were encountered: