area1707/grace-shopper

Single User Thunk and Route might come in handy

Opened this issue · 0 comments

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)
})