Skip to content Skip to sidebar Skip to footer

Counter Does Not Increment Or Decrement React

import React, { useState } from 'react'; const Quantity = ({ todo }) => { const [count, setCount] = useState(+todo.count); function decrementCount() { setCount(count -

Solution 1:

The issue was with your update function in index.js. Here is the updated code:

 app.put("/todos/:id", async (req, res) => {
     try {
         const { id } = req.params;
-        const { description } = req.body;
+        const { newCount } = req.body;
         const updateTodo = await pool.query(
-            "UPDATE todo SET description = $1 WHERE todo_id = $2",
-            [description, id]
+            "UPDATE todo SET count = $1 WHERE todo_id = $2",
+            [newCount, id]
         );

Post a Comment for "Counter Does Not Increment Or Decrement React"