File size: 606 Bytes
6242a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createStore } from 'zustand/vanilla';

type SelectedTab = 'history' | 'pending';

type SharedState = {
  uiAsTab: boolean;
  selectedTab: SelectedTab;
};

type SharedActions = {
  setSelectedTab: (tab: SelectedTab) => void;
};

export const createSharedStore = (initialState: SharedState) => {
  const store = createStore<SharedState>(() => initialState);
  const { getState, setState, subscribe } = store;

  const actions: SharedActions = {
    setSelectedTab: (tab: SelectedTab) => {
      setState({ selectedTab: tab });
    },
  };

  return { getState, setState, subscribe, ...actions };
};