Error: Actions must be plain objects. Use custom middleware for async actions in redux

前端 未结 3 1719
遇见更好的自我
遇见更好的自我 2021-01-22 20:04

Below is the code for my action creator:

export function fetchPosts()
  {
    const request = axios.get(`${ROOT_URL}/posts${API_KEY}`);
    return
      {
               


        
3条回答
  •  清歌不尽
    2021-01-22 20:44

    When you replace , with ; you get an error because, as stated by your error message, an action must return a JavaScript object.

    In JavaScript object properties should be separated by , as:

    return
          {
            type: FETCH_POSTS, // use comma here
            payload: request   
          };
    

    In this way the return statement will return a new object with two properties type and payload.

提交回复
热议问题