blob: e430aad296a64bcd20bad9b6f9255acd4c2fe7b3 [file] [log] [blame]
idillond858c182022-09-16 13:18:26 -04001import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2import type { RootState } from "./store";
3
4// Define a type for the slice state
5interface appState {
idillon531b6f22022-09-16 14:02:00 -04006 accountId: string;
idillond858c182022-09-16 13:18:26 -04007}
8
9// Define the initial state using that type
10const initialState: appState = {
idillon531b6f22022-09-16 14:02:00 -040011 accountId: "",
idillond858c182022-09-16 13:18:26 -040012};
13
14export const appSlice = createSlice({
15 name: "app",
16 // `createSlice` will infer the state type from the `initialState` argument
17 initialState,
18 reducers: {
idillon531b6f22022-09-16 14:02:00 -040019 setAccountId: (state, action: PayloadAction<string>) => {
20 state.accountId = action.payload;
idillond858c182022-09-16 13:18:26 -040021 },
22 },
23});
24
idillon531b6f22022-09-16 14:02:00 -040025export const { setAccountId } = appSlice.actions;
idillond858c182022-09-16 13:18:26 -040026
27// Other code such as selectors can use the imported `RootState` type
idillon531b6f22022-09-16 14:02:00 -040028// export const selectCount = (state: RootState) => state.app.value;
idillond858c182022-09-16 13:18:26 -040029
30export default appSlice.reducer;