mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
docs: strict null check in createContext example (#2995)
* docs: prefer useState in createContext example Both useState and useRef are correct in practice: useState will only render once since we never set the state after initializion, and useRef is safe to use since the component never needs to rerender when the ref value changes. However, lint rules will flag useRef as a mistake, because we are passing a ref value to a child component, which in general can cause stale components since changing refs doesn't trigger re-renders. * formatting * explicit null check
This commit is contained in:
parent
6c7699cc16
commit
17e281fd75
@ -118,7 +118,7 @@ const StoreContext = createContext(null)
|
||||
|
||||
const StoreProvider = ({ children }) => {
|
||||
const storeRef = useRef()
|
||||
if (!storeRef.current) {
|
||||
if (storeRef.current === null) {
|
||||
storeRef.current = createStore((set) => ({
|
||||
// ...
|
||||
}))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user