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

121
Views
Pass data via on click from child component to parent component react

I am new to React and trying to pass data (director, nonDirector) from my child functional component to a parent class component.

My code is below, what do I need to do to make it work?

Class parent component

export default class ProfileEditor extends React.Component<IProfileEditorProps, IProfileEditorState> {
    
      constructor(props: IProfileEditorProps) {
        super(props);
        this.state = {
          data: null,
        }
         this.updateProfile = this.updateProfile.bind(this);
      }

    public updateProfile(director, nonDirector) {

        console.log('hello', director, nonDirector);

     }

      <MultiSelect
        options={ profile?.Declarations.length == 0 ? countries : this.combineProfileAndCountrys() }   
        updateProfile={updateProfile()}
      />

Child functional component

export const MultiSelect = ({ options, updateProfile }) => { 

const [nonDirector, setNonDirector] = React.useState();
const [director, setDirector] = React.useState();

<PrimaryButton text='Save' onClick={ updateProfile(nonDirector, director) } />
    </Fragment>
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your parent component you shouldn't be calling the function in the onClick handler. You want to pass the reference to the function to it instead.

updateProfile={updateProfile}

A similar issue is occurring in your child component. You don't want to call the function and have the results of it returned to the handler, you want to assign a function to the handler that can then call the updateProfile function when its triggered.

onClick={() => updateProfile(nonDirector, director)}
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!