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

138
Views
call props function with parmeters from child

I want to call function with paramter from child compponent, i pass the function as a props and when i call this function its get to her but the paramter that i pass to the function is undiffend.

how can i call this function and send to her parmetrs?

here is my code:

perent function:

  async function doSomething(param){
//here i see in debug that param is undiffend
var do = param*2
console.log(do)
}

the call of the child componnet:

<child doSomething ={()=>doSomething()}/>

child:

export default function child(props) {
    const { doSomething} = props;
return (
            <div  onClick={() => doSomething(3)}>
           <button></button>
            </div>
    
)
 }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pass the function as a reference:

<Child doSomething={doSomething} />

or proxy the args through if you want to keep the anonymous callback function:

<child doSomething ={(...args) => doSomething(...args)} />

Child invokes the function and passes arguments:

export default function Child(props) {
  const { doSomething} = props;
  return (
    <div onClick={() => doSomething(3)}>
      ....
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

you do not need to call function when passing into child component just type like this:

<Child doSomething={doSomething}/>
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!