Answer the question
In order to leave comments, you need to log in
Error when logging in dispatch?
interface user:
export interface IUser {
email: string;
password: string;
id: number;
role: string;
createdAt: Date;
}
export function setUser(user: IUser): IActionUser {
return {
type: "SET_USER",
payload: user
}
}
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
})
})
}
}
Argument of type 'void' is not assignable to parameter of type 'IActionUser'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question