-
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Store:
export const useBudgetStore = createStore(
temporal<BudgetStore>(
(set, get) => ({
data: null,
isLoading: false,
error: null,
onPushBudgetItem: (item: BudgetDataItem) => {
set((state) => {
if (!state.data) return state;
return {
data: {
...state.data,
data: [...state.data.data, item],
},
};
});
},
fetchData: async (date: string) => {
set({ isLoading: true, error: null });
const { data, error } = await getByDate(date);
if (!error) {
set({ data, isLoading: false });
return;
}
set({ error: error.message, isLoading: false });
},
})
},
),
);
export const useTemporalStore = <T extends unknown>(
selector: (state: TemporalState<BudgetStore>) => T,
equality?: (a: T, b: T) => boolean,
) => useStore(useBudgetStore.temporal, selector, equality);
Component:
const store = useBudgetStore();
const { undo, redo, pastStates, futureStates } = useTemporalStore();
const handleAddRow = () => {
const item = newBudgetItem();
store.onPushBudgetItem(item);
setEditable([item.id, "budget"]);
};
My application works fine without using undo. However, I am adding items using the handleAddRow function which modifies my state. When I call the undo function, my store becomes undefined. Am I missing something to configure?
Metadata
Metadata
Assignees
Labels
No labels