• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

193
Views
Call a component's onChange method inside another one in React

There is a Selector component of this form:

<Selector
  initialSelectedOption={data[0].type}
  onChange={(val) => changeValue(val.name)}
  options={valueOptions}
/>;

when the user selects a value from the dropdown, onChange is called and the value is updated in the selector.

I want to reset the value to the original one once the user has clicked cancel:

 <Button onClick={handleCancel} />
...

  const handleCancel = () => {
    changeValue(data[0].type);
  };

However, something is wrong here as it is not called.

Is it a way to call the Selector's onChange method from handleCancel?

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

0

We need a bit more context to know for sure, but in general, you should define onChange in a parent component and pass it as a prop to both the selector component and the component that handles the cancel.

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error