Typescript conflict when using vanilla create #959
-
I have a non-react file with helper methods that will need to access and set global state An example import create from 'zustand/vanilla'
type User = {
username: string
id: number
}
interface GlobalStoreType {
authError: string | null
setAuthError: (err: string) => void
user: User | null
setUser: (user: User | null) => void
}
const store = create<GlobalStoreType>((set) => ({
authError: null,
setAuthError: (authError: string | null) => set(() => ({ authError })),
user: null,
setUser: (user: User | null) => set(() => ({ user })),
}))
export default store I need to access the store in a non react file
gives off the a typescript error of
setUser is just one of the four errors |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
May 16, 2022
Replies: 1 comment
-
It's not just TS, but JS usage. Please try this: const { authError, setAuthError, user, setUser } = store.getState() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
francis-chang
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not just TS, but JS usage. Please try this: