We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
import { listenKeys } from 'nanostores' import { useCallback, useSyncExternalStore } from 'react' export function useStore(store, opts = {}) { let subscribe = useCallback( onChange => opts.keys ? listenKeys(store, opts.keys, onChange) : store.listen(onChange), [opts.keys, store] ) let get = store.get.bind(store) return useSyncExternalStore(subscribe, get, get) }
isn't it better to use useSyncExternalStoreWithSelector to replace listening for keys ? example
const atom = Atom({name: 'jo', age : 21}) const age = useStore(atom, (state)=> state.age) // and only re-renders when the age is changes
The text was updated successfully, but these errors were encountered:
useSyncExternalStoreWithSelector is some kinda experimental api and not part of react. Using it would require to install additional package.
Sorry, something went wrong.
No branches or pull requests
isn't it better to use useSyncExternalStoreWithSelector to replace listening for keys ?
example
The text was updated successfully, but these errors were encountered: