area1707 / grace-shopper

3 stars 0 forks source link

Single User Thunk and Route might come in handy #53

Open rkaur01 opened 7 years ago

rkaur01 commented 7 years ago

In reducers/users

export const fetchSingleUser = () => dispatch => {
  axios.get(`/api/users/${id}`)
        .then(res => dispatch(init(res.data)))
}

In server/api/users

//matches GET requests to /api/users/:userId
router.get('/:userId', function (req, res, next) {
  User.find(
    {
      where: {id:req.params.userId}
    })
  .then( user => res.status(200).json(user))
  .catch(next)
})