Skip to content

Instantly share code, notes, and snippets.

@astrarudra
Last active May 25, 2024 13:34
Show Gist options
  • Save astrarudra/66ce6f5b3569965be622a4b0e8fd1124 to your computer and use it in GitHub Desktop.
Save astrarudra/66ce6f5b3569965be622a4b0e8fd1124 to your computer and use it in GitHub Desktop.
zustand-controller - Setup Store
import { createWithEqualityFn }
from 'zustand/traditional'
import { immer } from 'zustand/middleware/immer'
import { shallow } from 'zustand/shallow'
/* I named it OxyStore - Using
createWithEqualityFn for Default Equality fn. */
const useOxyStore = createWithEqualityFn(
immer(// Immutable State & no return required.
(...o) => ({
...generalSlice(...o),
...notificationSlice(...o),
}) // Split into slices for extensibility.
)
)
, shallow) // 2nd param of createWithEqualityFn.
export useOxyStore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment