I have a form that I'm trying to use to update a React component. The state seems to be altered because it re-renders no problem when I hit submit, but the data doesn't persist. More importantly, I get a 404 saying that the json object I'm trying to change can't be found.
I think it's something to do with how I'm trying to use my axios request in my actions, but I wouldn't be surprised if I'm off base from looking at this for too long.
Here are the relevant tidbits
Routes
const User = db.model('user')
const router = require('express').Router();
router.put('/:id', (req, res, next) => {
User.findById(req.params.id)
.then(user => user.update(req.body))
.then(updated => res.status(201).json(updated))
.catch(next)
})
Actions
const editUser = (userId, userInfo) => ({
type: UPDATE_USER,
userId,
userInfo
})
export const updateUser = function(id, info) {
return dispatch => {
dispatch(editUser(id, info))
axios.put(`/api/users/${id}`, {info})
.catch(err => console.error("Wasn't able to update user.", err))
}
}
Here are the errors I'm getting
POST http://localhost:1337/api/users/1 Wasn't able to update property. 404 (Not Found)
Error: Request failed with status code 404
at createError (createError.js:15)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
And that URI totally exists, so I don't really see why the request seems to think otherwise.
Any help is appreciated!
Figured it out. Needed an extra line using .then to actually send the information to the my db.
export const updateUser = function(id, info) {
return dispatch => {
dispatch(editUser(id, info))
axios.put(`/api/forSale/${id}`, info)
.then(res => res.data)
.catch(err => console.error("Wasn't able to update property.", err))
}
}