TS: Uncaught Reference error with async actions / services in react ts

140 Views Asked by At

I am working on react typescript project where i have login action for user authentication. It is working fine and return result. Below is my function

export const login = (email: string, password: string) => {
        return axios.post('auth/login',{
            email,
            password
        }).then(response => {
            return response.data;
        })
    }

but when I tried to use async with it to update my redux state by using await and dispatch like below

export const login = (email: string, password: string) => {
  return async (dispatch) => {
    (async () => {
        const res = await axios.post('auth/login',{
            email,
            password
        }).then(response => {
            return response.data;
        });
        dispatch({type:'AUTHENTICATION',payload: res})
    })();
};

}

I get an error and application crashes.

app.js:4239 Uncaught ReferenceError: exports is not defined

Uncaught reference error

I Tried multiple solutions but not working at all. Currently I am using dispatch inside component to update state. I want to do that in action using async await and dispatch. I used the same approach in many other react projects and it worked without any issue. But Its my first time with typescript and I am not able to solve it.

0

There are 0 best solutions below