Unable to use zustand in vanilla project #2322
Answered
by
dbritto-dev
trigun539
asked this question in
Bug report
-
|
I'm getting following error when in a vanilla app: Cannot read properties of null (reading 'useRef')
TypeError: Cannot read properties of null (reading 'useRef')
at useRef (webpack://simple/./node_modules/react/cjs/react.development.js?:1631:21)
at useSyncExternalStoreWithSelector (webpack://simple/./node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js?:51:17)
at useStore (webpack://simple/./node_modules/zustand/esm/index.mjs?:27:17)
at SettingsButton (webpack://simple/./src/components/SettingsButton.ts?:14:86)Store File: import { createStore } from 'zustand/vanilla'
interface SettingsState {
clicked: boolean
setClicked: (clicked: boolean) => void
}
const useSettingsStore = createStore<SettingsState>((set) => ({
clicked: false,
setClicked: (clicked: boolean) => set({ clicked }),
}))
export default useSettingsStoreUsage in other file: import * as PIXI from 'pixi.js'
import { Button } from '@pixi/ui'
import { useStore } from 'zustand'
import SettingsStore from '../stores/settings-store'
const SettingsButton = () => {
const { clicked, setClicked } = useStore(SettingsStore)
return new Button()
} |
Beta Was this translation helpful? Give feedback.
Answered by
dbritto-dev
Feb 9, 2024
Replies: 1 comment 4 replies
-
|
@trigun539 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

@trigun539 the docs point that you can use a vanilla store in react using the
useStorehook. Don't forget that the hook thing is often related to react stuff