0

I have a button in the parent component and I want to pass that click action to the child component, when I click the button I want to use that click to get data from backend, the point is just to pass click action or function to child


const parent = ()=>{
return (
<>
<button onclick={handlcklick}>Click me</Button>
</>
)

}

use that handlclick in child


const child = ()=>{
const handlclick =(e)=>{
alert("hello")
}
return (
<>
</>
)

}
amghare
  • 101
  • 8
  • Does this answer your question? [Call child method from parent](https://stackoverflow.com/questions/37949981/call-child-method-from-parent) – SuleymanSah Oct 28 '22 at 17:45

1 Answers1

0

If there is no dependency on the parent component better to use that function inside the child component to avoid more props drilling.

Elvin
  • 565
  • 1
  • 5
  • 12
  • i cant because childe i use it like header where i get query by input and the other button is in body and I want to use that to get that query – amghare Oct 28 '22 at 17:57