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

130
Views
is onChange triggered if the value is changed by parent?
const [value, set_value] = useState({a: 1});

<Child
  value={value}
  onChange={callback}
</Child>

set_value({a: 2})

When set_value({a: 2}) is run, will that trigger the callback inside of the onChange to run?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think the most exact answer to the question is:
"That is up to the <Child> component."

From Reacts point of view value and onChange are just two properties of <Child>, so:
No, changing one property (value) doesn't necessarily cause any callbacks (onChange) to be called.

But it is common in React to have so called "controlled-components", where the state (i.e. the value) is kept inside the parent, and the child doesn't have any own state, but will receive the value from the parent, and only informs the parent about changes.

In your example the parent component keeps the state:

const [value, set_value] = useState({a: 1});

And the child might only receive the value and call the callback if changes are necessary (but doesn't keep any own state), e.g.:

const Child = function( props ){
  return <button onClick={ function(){
    props.onChange( props.value.a + 1 );
  }}>
    { props.value.a }
  </button>
};
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!