interface user:
export interface IUser {
email: string;
password: string;
id: number;
role: string;
createdAt: Date;
}
user action:
export function setUser(user: IUser): IActionUser {
return {
type: "SET_USER",
payload: user
}
}
login hanlder:
const loginHandler = (event:any) => {
return (dispatch:React.Dispatch<IActionUser>) => {
event.preventDefault();
axios({
method: "POST",
url: "http://localhost:5000/api/user/login",
data: user,
headers: {
"Content-Type": "application/json"
}
})
.then((response) => {
Cookies.set("token", response.data.token);
history.push("/");
dispatch(setUser(user)); // error
})
.catch((err) => {
setAlert({
type: "error",
message: err.message
})
})
}
}
Error:
Argument of type 'void' is not assignable to parameter of type 'IActionUser'