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

113
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!