Search code examples
javascriptreactjspostaxioses6-promise

.then() of axios.post is not functioning


I am super new to React and JS. So I am developing simple application of user management using React and Nodejs. I use axios.post to add users. Because of I need to get response from back end I used then() function but Code doesn't reach to then function. Am I doing it correct or is there another way to approach?

export const addUser = (data) => {
return (dispatch) => {
                    dispatch(AssignUser(data));
                    dispatch(showForm());
                    return axios.post('http://localhost:4000/admin/add', data)
                        .then((res) => {
                            console.log('Inside then')
                        })
                        .catch(error => {
                            throw(error);
                        });
                }
};

dispatch use for redux functionalities. I tried removing return statements of the function and used async,await as well. console.log doesn't print. Thanks in advance if you can help.


Solution

  • Just noob issue. Back-end end response did't come. Always check your back-end with postman or any other tool. @user3791775 Thank you every one for your time.