Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created May 2, 2021 19:28
Show Gist options
  • Save AllGistsEqual/ded6ebf9bad0c176e7686073427932ff to your computer and use it in GitHub Desktop.
Save AllGistsEqual/ded6ebf9bad0c176e7686073427932ff to your computer and use it in GitHub Desktop.
// File: src/redux/ducks/appState.ts
import { createAction, createReducer } from '@reduxjs/toolkit'
import { RootState } from '../index'
type AppState = {
isRunning: boolean
}
const initialState: AppState = {
isRunning: false,
}
export const setRunning = createAction('[APPSTATE] Set Running', (running: boolean) => ({
payload: {
running,
},
}))
export const selectIsRunning = (state: RootState): boolean => state.appState.isRunning
const appStateReducer = createReducer(initialState, builder => {
builder.addCase(setRunning, (state, action) => {
const { running } = action.payload
return {
isRunning: running,
}
})
})
export default appStateReducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment