React variable value never getting used in find function

  javascript, reactjs

Take a look at the code below. I’m passing userId into my action but it’s value is never being used. Maybe I’m using the find function in a wrong way, some help is appreciated.

export const getUserInfo = (userId) => dispatch =>{
    axios.get("http://localhost:5000/users")
    .then((res) =>{
        const userInfo = res.find((userId) =>{
            return res.data.id === userId;
        })
        dispatch({
            type: USER_INFO,
            payload:  userInfo
        })
    })
}

Source: Ask Javascript Questions

LEAVE A COMMENT