redux - 在另一个动作中调用 redux 动作不起作用
问题描述
我有控制台记录错误并且错误在控制台中可见但setAlert操作没有调度,这是为什么呢?
这是身份验证操作代码
import axios from "axios"
import {setAlert} from "../actions/alert";
import { REGISTER_FAIL } from "./conts"
export const register = ({ name, username, email, password }) => async dispatch => {
const config = {
headers: {
'Content-Type': 'application/json'
}
}
const body = JSON.stringify({ name, username, email, password });
try {
const res = await axios.post("http://localhost:8080/signup",body,config);
setAlert("Email has been sent..! Please Confirm Your email","success",10000) //not working
}
catch (err) {
console.log(err.response.data.error);
const error = err.response.data.error;
setAlert(error,"error",5000); //not working
dispatch({
type:REGISTER_FAIL
});
}
}
这是警报动作
import {SET_ALERT,REMOVE_ALERT} from "./conts";
import {v4 as uuidv4} from "uuid";
export const setAlert =(msg,alertType,timeOut =5000)=> dispatch=>{
const id= uuidv4();
dispatch({
type: SET_ALERT,
payload:{msg,alertType,id}
});
setTimeout(()=> dispatch({type:REMOVE_ALERT,payload:id}),timeOut)
}
解决方案
好吧,看来,我只需要发送 setAlerts
推荐阅读
- c - 在 C 中进行字符串操作时遇到分段错误
- react-navigation - React Navigation v5 为所有屏幕设置 StatusBar barStyle
- c - 指针声明和定义如何对指针起作用?
- python - Pytorch - 使用预训练模型,分类器训练
- scala - 如何在scala seq中每个元素的开头和结尾附加char?
- python - 如何使用具有不同属性的同一类生成多个对象?
- jsf-2 - 用于包含模板时,Mojarra 与 MyFaces 中 ui:param 的不同行为
- python - 如何使用 Pandas 查找所有以男性和女性为主的职业列表
- python - 未配置 Django 设置
- regex - 基于属性及其值的存在的正则表达式