I have three components: ComponentA, ComponentB and Home (Home is the component parent). I want to call a function contains in ComponentA
using a button that is inside of ComponentB
.
const ComponentA= () => {
const hello=()=>{
console.log("hello");
}
return <></>
})
const ComponentB= () => {
const callComponentAFunction=()=>{
// I need call "hello()" from ComponentA
}
return
<>
<button onClick={callComponentAFunction}>Call function from ComponentA</button>
</>
})
const Home= () => {
return
(<>
<ComponentA>
<ComponentB />
</ComponentA>
</>)
})
How can I call hello()
function (inside of ComponentA
) from ComponentB
?