Skip to content

Instantly share code, notes, and snippets.

@Blithe-Chiang
Created May 12, 2024 03:02
Show Gist options
  • Save Blithe-Chiang/6bb07a94ae9fc67d1ff1af2d45b3ae1a to your computer and use it in GitHub Desktop.
Save Blithe-Chiang/6bb07a94ae9fc67d1ff1af2d45b3ae1a to your computer and use it in GitHub Desktop.
zustand简单封装
// deps: zustand, immer
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
export type TStore<T> = ReturnType<typeof createStore<T>>
export function createStore<T>(initState: T) {
return create<T>()(
immer((set) => ({
...initState
}))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment