React + redux error

after login button press I want to check whether fields are empty or not. But I faced this error.
Error: Actions must be plain objects. Use custom middleware for async actions. This is my code.

export const loginUser = (user) => {
  return (dispatch) => {
    console.log("checker");
    axios.post('/api/users/login', user)
      .then(res => {
        console.log(res.data);
      })
      .catch(err => {
        dispatch({
          type: GET_ERRORS,
          payload: err.response.data
        });
      });
  }
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

1 Like

You need other libraries to handle async actions in redux. Take a look at

Redux-Thunk and Redux-Saga.

1 Like