nav2/lib/store.ts
Primakov Alexandr Alexandrovich fd0eb66563 useSyncExternalStore
2024-11-12 20:06:45 +03:00

17 lines
387 B
TypeScript

export const createStore = (initialState) => {
let state = initialState
const listeners = new Set<() => void>()
return {
getState: () => state,
subscribe: (listener) => {
listeners.add(listener)
return () => {listeners.delete(listener)}
},
setState: (newState) => {
state = newState
listeners.forEach((listener) => listener())
},
}
}