Skip to content
Discussion options

You must be logged in to vote
import { create } from "zustand";
import { devtools, persist } from "zustand/middleware";

type State = {
  sourceRole: { id: number; sourceName: string; sourceRole: string } | null;
};

type Actions = {
  setSourceRole: (sourceRole: State["sourceRole"]) => void;
};

export const useSidebarStore = create<State & Actions>()(
  devtools(
    persist(
      (set) => ({
        sourceRole: null,
        setSourceRole: (sourceRole) => set(() => ({ sourceRole })),
      }),
      { name: "sidebar-store" }
    )
  )
);

@aaronfulkerson on ts should be create<T>()(...) or createStore<T>()(...)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aaronfulkerson
Comment options

Answer selected by aaronfulkerson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants