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

115
Vistas
Problem with changing values of State Hook which is an object

I have rather simple problem.

I don't know why my useState function won't change state -> props

onChangeText={(text) => {
  setProps({ ...props, inputValue: text });
}}

I declared my state as here:

const [props, setProps] = useState({
  pageNumber: 2,
  inputValue: "",
});

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

prevState received by the updater function is guaranteed to be up-to-date. It's a reference to the component state at the time the change is being applied. Official docs

onChange={(event) => {
    setProps(prevState => {
       return { ...prevState, inputValue: event.target.value }
    });
}}

Also if you have input just use native event onChange instead of custom onChangeText

about 4 years ago · Juan Pablo Isaza Denunciar

0

You wrote 'onChangeText' instead of 'onChange'. And, it gives you the event object rather than the text itself. It should be like this:

    <input onChange={(event) => {
        setProps({ ...props, inputValue: event.target.value });
      }} />
about 4 years ago · Juan Pablo Isaza Denunciar

0

What you doing is correct and nothing is wrong with it.

you need to pass your state value to the input

import { useState } from "react";

export default function App() {
  const initialState = {
    pageNumber: 2,
    inputValue: ""
  };

  const [props, setProps] = useState(initialState);

  const textInputChangeHandler = (e) => {
    setProps({ ...props, inputValue: e.target.value });
  };

  return (
    <div className="App">
      <input
        value={props.inputValue}
        type="text"
        onChange={textInputChangeHandler}
      />
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Denunciar
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