A
A
Alexey Yakovlev2022-04-07 22:07:41
typescript
Alexey Yakovlev, 2022-04-07 22:07:41

Error when logging in dispatch?

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 handler:
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'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question