-
Hi, I am new to Zustand, and curious how to use vanilla Zustand store (created by React Tracked's documentation only talks about using Ahh, my project is using TypeScript. Thanks all. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a bit tricky and not 100% recommended hook pattern, but something like this should work: import { createContext, useContext } from 'react'
import { createStore, useStore } from 'zustand'
import { createTrackedSelector } from 'react-tracked'
const store = createStore(...) // vanilla store without hooks
const StoreContext = createContext()
const App = () => (
<StoreContext.Provider value={store}>
...
</StoreContext.Provider>
)
const Component = () => {
const store = useContext(StoreContext)
const useTrackedStore = useMemo(() => createTrackedSelector(
(selector) => useStore(store, selector)
), [store])
const state = useTrackedStore()
...
} (...Not exactly sure if this handles changing |
Beta Was this translation helpful? Give feedback.
This is a bit tricky and not 100% recommended hook pattern, but something like this should work:
(...Not exactly su…