I am doing the React nanodegree that Udacity offers and am working on the second project, Readable. I have this code below that attempts to update a post with a new score.
handleVote = (vote) => {
console.log(vote);
const url = `${process.env.REACT_APP_BACKEND}/posts/` + this.props.id;
fetch(url, { credentials: 'include',
option : "" + vote,
headers: { 'Authorization': 'whatever-you-want' },
method: 'POST'
}
).then((response) => response.json()
.then((json) => { console.log(json) })
.catch((errors) => { console.log(errors); }));
}
I get a response back but it seems to have the same score. I'm not sure what I am doing wrong. I've tried adding the string as an option and also to the body. The "vote" is the string "upVote" or "downVote".
In the documentation they provide all they have this:
| `POST /posts/:id` | Used for voting on a post. | **option** - [String]: Either `"upVote"` or `"downVote"`. |
If anyone has done this project before I would love the help. I'm not really sure where to specify the "upVote" or "downVote" in the request.