Skip to content

Zustand use in webworker

Posted on:August 20, 2023 at 01:30 PM

use proxy to sync actions to main thread


import { createStore } from 'zustand/vanilla'

const useBearStore = createStore((set) => ({
    appble: 0,
    increasePopulation: () => set((state) => ({ appble: state.bears + 1 })),
    removeAllBears: () => set({ appble: 0 }),
}))

const { getState, setState, subscribe } = useBearStore