I am new to react. Basically I want that when I click on the button of the child component, the function myFunction is called from the parent component. How can I do it?
import "./styles.css";
export const Parent = ({ children }) => {
//I need excecute myFunction when user click
return (
<div>
I am parent <br />
<br /> {children}
</div>
);
};
export const Child = () => {
const myFunction = () => {
console.log("say hello from parent");
};
return (
<div>
I am children
<br />
<button>Send function to execute in the parent</button>
</div>
);
};
export default function App() {
return (
<Parent>
<Child />
</Parent>
);
}