I want to store the response from an API call to the state
. Whenever I refresh the page it losses its data/values. I wrote a saga for it
export function* maintainCurrentUserState(action) {
if (!this.action) {
yield put(getCurrentUserSaga());
}
}
but this does not make any sense. Basically, my approach is to recall the getCurrentUserSaga()
method when it the data is not found in the state.
This is the component for the same
componentDidMount() {
this.props.getCurrentUser();
bsCustomFileInput.init();
}
...
const mapStateToProps = state => {
return {
loading: state.getCurrentUser.loading,
error_messages: state.getCurrentUser.errors,
response: state.getCurrentUser.successMessage
};
};
const mapDispatchToProps = dispatch => {
return {
getCurrentUser: () => dispatch(actions.getCurrentUser())
};
};
export default compose(
withTranslation(),
connect(mapStateToProps, mapDispatchToProps)
)(ProfileSettings);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…