import { ChatState } from "@/lib/constant"; import { create } from "zustand"; type State…
- User
import { ChatState } from "@/lib/constant"; import { create } from "zustand";
type State = { threadId?: string | null; chatStates: ChatState[]; };
type Actions = { setThreadId: (threadId: string | null) => void; addState: (chatState: ChatState) => void; setStates: (chatStates: ChatState[]) => void; deleteStates: (chatStates: ChatState[]) => void; };
export type WritingState = State & Actions;
export const useWritingStore = create((set) => ({ threadId: null, chatStates: [], setThreadId: (threadId: string | null) => set({ threadId }), addState: (chatState: ChatState) => set((state) => ({ chatStates: [...state.chatStates, chatState] })), setStates: (chatStates: ChatState[]) => set({ chatStates }), deleteStates: (chatStates: ChatState[]) => set({ chatStates = ChatState[] }), })); 0------- 帮我优化一下deleteStates
- Assistant
To optimize the
deleteStatesfunction in your Zustand store, we can modify it to remove specificChatStateentries from thechatStatesarray instead of trying to set the state to an erroneous assignment likechatStates = ChatState[]. This would involve filtering thechatStatesarray to exclude the states that you want to delete.