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

128
Vistas
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 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