perf(mod queue): reduce loading rerenders

This commit is contained in:
Tommaso Casaburi
2026-04-27 14:59:24 +07:00
parent 5dc5408a15
commit abaa0d4e16
6 changed files with 138 additions and 9 deletions
+15 -1
View File
@@ -2,12 +2,26 @@ import { create } from 'zustand';
interface FeedResetState {
reset: (() => void) | null;
currentResetFunction: (() => void) | null;
setResetFunction: (resetFunction: () => void) => void;
}
const invokeCurrentResetFunction = () => {
useFeedResetStore.getState().currentResetFunction?.();
};
const useFeedResetStore = create<FeedResetState>((set) => ({
reset: null,
setResetFunction: (resetFunction) => set({ reset: resetFunction }),
currentResetFunction: null,
setResetFunction: (resetFunction) =>
set((state) =>
state.currentResetFunction === resetFunction && state.reset
? state
: {
currentResetFunction: resetFunction,
reset: state.reset ?? invokeCurrentResetFunction,
},
),
}));
export default useFeedResetStore;