UseContext & fetch
Answered
Asiatic Lion posted this in #help-forum
Original message was deleted.
Answered by not-milo.tsx
Add an api call to your counter increment/decrement buttons. When the user interacts with them they update your counter db table and if the operation succeeds you update your context state to reflect the new value stored in the database
12 Replies
Add an api call to your counter increment/decrement buttons. When the user interacts with them they update your counter db table and if the operation succeeds you update your context state to reflect the new value stored in the database
Answer
Since you're updating an existing record I'd use the PUT method. POST is generally used when you're inserting new data into the database
Also, the PUT http method is idempotent meaning that two identical requests made at the same time modify the record only once.
Original message was deleted
I'm not sure I understood the question...
Original message was deleted
LGTM ðŸ‘ðŸ»
Now you just have to update the context state accordingly.
And if you need it you can also denounce the buttons to avoid multiple requests being made in a really short time span.
Now you just have to update the context state accordingly.
And if you need it you can also denounce the buttons to avoid multiple requests being made in a really short time span.
Original message was deleted
You should probably send it as
{ counter: number } and not { counter: { someObject } }There's no body in the screenshot you sent... 👀
There's something wrong with your GET method implementation... The endpoint should be returning a counter object regardless of the response you get from the database...
If you link me the repository I can take a closer look tomorrow. Rn I better get some sleep lol
It could be... It could be a lot of things
Original message was deleted
It's ok, you don't have to know it to upload the code to a GitHub repo.
But anyways I'll take a look at the code you sent above tomorrow morning ✌ï¸
But anyways I'll take a look at the code you sent above tomorrow morning ✌ï¸
Great, you figured it aout already 
