【发布时间】:2021-02-13 00:49:16
【问题描述】:
我有一个带有 React-Redux 的登录系统,我想在发送特定调度类型时显示 JSX。
例如,当登录系统失败时,调度类型为LOGIN_FAIL,我想显示一条错误消息,但当身份验证成功时,调度类型为LOGIN_SUCCESS,我想显示一条成功消息。我已经通过 mapStateToProps 访问了用户名,但我很好奇是否有另一种通过调度类型进行条件渲染的方法?
感谢您对该主题的建议或提示。
这是我的actions.js:
export const login = (email, password) => async dispatch => {
const config = {
headers: {
'Content-Type': 'application/json'
}
};
const body = JSON.stringify({ email, password });
try {
const res = await axios.post(`${process.env.REACT_APP_API_URL}/auth/jwt/create/`, body, config);
dispatch({
type: LOGIN_SUCCESS,
payload: res.data
});
dispatch(load_user());
} catch (err) {
dispatch({
type: LOGIN_FAIL
});
}
};
【问题讨论】:
标签: javascript reactjs redux react-redux