reactjs - React + Redux Login
问题描述
I'm finding a problem that I can not find an optimal solution,
Well, the problem involves Redux, when making a request in the Login route, to receive the Token. The middleware that will handle the result of the request always returns with payload = undefined.
If I make any promises using this middleware, it usually returns the result, but when it is login, it tries to do SET before receiving the result.
middleware: https://textuploader.com/dnp0m
Reducer Auth: https://textuploader.com/dnp0q
Reducer Common: https://textuploader.com/dnp0c
Agent: https://textuploader.com/dnp0l
Im Calling the dispatch like this
onSubmit: (cpf, pass) => {
dispatch({type: LOGIN, payload: agent.Auth.login(cpf, pass)})
},
解决方案
问题可能出在您的中间件中,当您查看中间件代码时,您正在更新 action.payload 对象本身。
res => {
console.log('RESULT', res);
action.payload = res;
store.dispatch({ type: ASYNC_END, promise: action.payload });
store.dispatch(action);
}
而不是更新 action.payload 值,只需发送 res 值。
res => {
console.log('RESULT', res);
store.dispatch({ type: ASYNC_END, promise: res });
store.dispatch(action);
}
推荐阅读
- sql - 用于在同一列的连续行中查找不同记录的 SQL 查询
- html - Flexbox 中的 CSS 网格突然中断
- excel - Excel If 或 Vlookup 以查看值是否等于 2 或 3
- sql - FOREIGN KEY 约束失败,SQLite
- python - 使用 tensorflow 数据集对象训练两个输入模型
- reactjs - 我有一个带有搜索栏的简单信使应用程序,每当我按退格键时,它都不会更新过滤器
- javascript - 如何将 HTML 表中的选定行发送到烧瓶并呈现新模板?
- python-3.x - 如果满足多个条件,如何将列的值设置为等于另一列?
- python - 如何将字典中的值与数字相乘以获得实际值?
- graphql - 即使是客户端错误,graphql 服务器是否总是返回 500?