mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
28 lines
730 B
TypeScript
28 lines
730 B
TypeScript
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,
|
|
currentResetFunction: null,
|
|
setResetFunction: (resetFunction) =>
|
|
set((state) =>
|
|
state.currentResetFunction === resetFunction && state.reset
|
|
? state
|
|
: {
|
|
currentResetFunction: resetFunction,
|
|
reset: state.reset ?? invokeCurrentResetFunction,
|
|
},
|
|
),
|
|
}));
|
|
|
|
export default useFeedResetStore;
|