Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Recibo un error indefinido cuando consuelo la variable de estado y muestro el valor correcto cuando consuelo en todas las variables utilizadas para el estado

Recibo un error indefinido en la variable de valor que es un estado, pero cuando consuelo la variable en la que se almacenan los datos, proporcione los datos correctos de la base de datos, pero cuando pongo esa variable para establecer el estado, muestra un valor indefinido.

 import React, { useState } from "react"; import { useEffect } from "react"; const TodoList = () => { const [Printed, SetDbData] = useState(); const getData = async () => { try { const getDbContent = await fetch("/getData", { method: "GET", headers: { Accept: "application/json", "Content-Type": "application/json", }, credentials: "include", }); const getDbData = await getDbContent.json(); const [object] = getDbData; SetDbData(object); console.log(object); //************** when i console object is Show data ************** { "_id": "62d145c8ea501901f8ad650d", "todoText": "hello", "__v": 0 } console.log(Printed); //************* but when i console state varriable (Printed )is Show undefined Data*********** (undefined) } catch (e) { console.log(e); } }; useEffect(() => { getData(); }, []); return ( <> <div className="container"> <div className="card"> <br /> <h1>Todo List</h1> <span></span> <br /> <form className="inner_card" method="POST" > <input type="text" name="todoText" placeholder="Add Items" autoComplete="off" /> <button type="submit" > + </button> <span className="warning_tag" id="span_id"> WARNING : Please Add Something </span> </form> </div> </div> </> ); }; export default TodoList;

Por favor, ¿alguien puede decirme dónde estoy cometiendo un error? Estoy seriamente atrapado en este problema. Por favor, ayúdame.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!