1
votes

I have a login form with a submit button that trigger handleSubmit function, in this function i am doing my axios stuff

 const handleSubmit = (e) => {  
     e.preventDefault();
     //action creator
     loginUser(loginData)
}

My Redux action creator:

export const loginUser = (loginData) => (dispatch) => {
    axios.post('/signin', loginData)
        .then(res => {
            let FBIdToken = `Bearer ${res.data.token}`;
            localStorage.setItem('FBIdToken', FBIdToken);
        })
        .catch(err => {
            dispatch({
                type: SET_ERRORS,
                payload: err.response ?  err.response.data : {}
            });
         })
 }   

Now after unmounting the login component i get that error:

index.js:1 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

I know what is my problem is , i need to clean up my axios request, How to clean axios request in my case??

I'd say you probably have a setState somewhere in your login component that's fired after umnounting. - k-wasilewski
Is it happening when the request is successful or not ? And what state is being updated the login component state ? - h1b9b
@k-wasilewski yes so why i am asking for a cleanup, all state managed by redux, the state fragment here is errors - Code Eagle
Where does the history object on loginUser comes from ? - h1b9b
@CodeEagle ok, so it would be easier to help if you provided us your complete code of index.js :) - k-wasilewski