Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
I am unable to update my column in my postgresql database
import React, { useState } from 'react';


const Quantity = ({ todo }) => {
  const [count, setCount] = useState(+todo.count);
  function decrementCount() {
    setCount(count - 1)
    updateCount(count - 1)
  }

  function incrementCount() {    
   setCount(count + 1)
   updateCount(count + 1)
 }

  // edit count function 

  const updateCount = async (newCount)  => {
    console.log("this is the newCount", newCount)  

  
  try {
     const body = { "newCount" : newCount}
     const response = await fetch(
      `http://localhost:5000/todos/${todo.todo.id}`,
       {
         method: "PUT",
         headers: { "Content-Type": "application/json" },
         body: JSON.stringify(body)
       }
     );
    
  

     window.location = "/";
    } catch (err) {
      console.error(err.message);
       
    }
   }


 return (
  <>
    <button onClick={() => decrementCount(count)}>-</button>
    <span>{count}</span>
    <button onClick= {() => incrementCount(count)}>+</button>
    </> 
  )
  }
  

export default Quantity; 

I am unable to get my counter app to update the "count" column in my postgresql table, any suggestions? Should I change todo.todo.id? or should I change count in regards to the onclick in the return statement?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda