0

I'm trying to pass in a value to the URL param after the axios call it does not go through. code below explains my problem:

export function fetchUser(id) {
  console.log(id) // works
 return function(dispatch, id) {
  console.log(id) // does not work
    axios.get("https://jsonplaceholder.typicode.com/users?id=" + id)
      .then((response) => {
        dispatch({type: "FETCH_USER_FULFILLED", payload: response.data})

      })
      .catch((err) => {
        dispatch({type: "FETCH_USER_REJECTED", payload: err})
      })
  }
}
2

1 Answer 1

2

You have used an id in your fetchUser function as well as in your return function.

export function fetchUser(id) {
console.log(id) // works
 return function(dispatch) {
  console.log(id) // will work
    .......
}

Try removing it from your return function like shown above

Or if you're using fetchUser as a middleware function, you can remove id as a param in fetchUser and add it as a param only in your return function

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.