Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda