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

131
Visualizações
usestate not picking up updated value
function Profile() {


    const [userId, setUserId] = useState(localStorage.getItem("user_id"))
    const [fname, setFname] = useState()
    const instance = axios.create({baseURL: server});

    useEffect( ()=> {
      
      const getUserValues = async () => {

        const response = await instance.get(
          `Users?id=${userId}`

        )
          setFname(response.data[0].fname)
          console.log(response.data[0].lname)
      }
      getUserValues();
    },[])



    const editValues = {
      firstname: fname,
    };

    const [editUserValue, setEditValue] = useState(editValues);


    console.log(fname) return( <input className="form-control" type="text" name="firstname" value={editUserValue.firstname} )

I'm having issues on getting my editvalues to display in the input because of the rendering that react has on usestate. In the console.log(fname) i get first a undefined then another console log of the value that is needed. But i cant get that value to display on the input.

The updated value should be taken by editvalues, but editvalues only takes the non updated data.

Any suggestions?

about 4 years ago · Juan Pablo Isaza
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