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

186
Views
I'm getting an undefined error when console the state variable and show correct value when i console acutall variable used for state

I'm getting an undefined error on value variable which is a state but when i console the variable in which data is Store it Give Correct Data From Data Base but when a put that varible to set state it show undefined Value.

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;

plaese Can Anyone tell my where i'm doing mistake i'm seriously stuck in this problem please help me

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!