Last active
July 6, 2021 07:06
-
-
Save manoj-mass/fc5f6667c59bceb5f036153b6dac126c to your computer and use it in GitHub Desktop.
redux header reducer - https://medium.com/@manojdarshana/reactjs-testing-with-jest-101-81bb17dd6c65
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
export const ACTION_TYPES = { | |
SET_HEADERDETAILS: 'SET_HEADERDETAILS', | |
}; | |
const initialState = { | |
headerTitle: '', | |
}; | |
export type HeaderState = Readonly<typeof initialState>; | |
// Reducer | |
export default (state: HeaderState = initialState, action): HeaderState => { | |
switch (action.type) { | |
case ACTION_TYPES.SET_HEADERDETAILS: | |
return { | |
...state, | |
headerTitle: action.payload.header, | |
}; | |
default: | |
return state; | |
} | |
}; | |
export const loadHeader: (header: string) => void = header => async (dispatch, getState) => { | |
await dispatch({ | |
type: ACTION_TYPES.SET_HEADERDETAILS, | |
payload: { header }, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment