Files
5chan/src/stores/use-challenges-store.ts
T
plebeius e556a9e662 chore(deps): replace plebbit/plebbit-react-hooks with bitsocialhq/pkc-react-hooks
bitsocialhq/pkc-react-hooks is a fork of plebbit-react-hooks that we're maintaining temporarily as an attempt to modernize the original repository using AI tools, possibly merging changes back into plebbit-react-hooks, which should also be rebranded to pkc-react-hooks eventually, under the org pkcprotocol.
2026-02-28 15:02:56 +08:00

29 lines
713 B
TypeScript

import { create } from 'zustand';
import { Challenge } from '@bitsocialhq/pkc-react-hooks';
let nextChallengeId = 0;
interface State {
challenges: Array<{ challenge: Challenge; id: number }>;
addChallenge: (challenge: Challenge) => void;
removeChallenge: () => void;
}
const useChallengesStore = create<State>((set) => ({
challenges: [],
addChallenge: (challenge: Challenge) => {
set((state) => ({
challenges: [...state.challenges, { challenge, id: nextChallengeId++ }],
}));
},
removeChallenge: () => {
set((state) => {
const challenges = [...state.challenges];
challenges.shift();
return { challenges };
});
},
}));
export default useChallengesStore;