import { createSlice } from '@reduxjs/toolkit' import { AppState } from './types' export const initialState: AppState = { loaded: false, loading: false, } export const appSlice = createSlice({ name: 'app', initialState, reducers: { initApp: state => { // Redux Toolkit allows us to write "mutating" logic in reducers. It // doesn't actually mutate the state because it uses the Immer library, // which detects changes to a "draft state" and produces a brand new // immutable state based off those changes // so you could have: // state.loading = true // state.loaded = false, or you can return state, but not both approaches. return { ...state, loading: true, loaded: false, } }, initAppSuccess: state => { return { ...state, loading: false, loaded: true, } }, initAppFailure: state => { return { ...state, loading: false, loaded: false, } }, }, }) export default appSlice