Skip to content

Instantly share code, notes, and snippets.

@itaditya
Created February 3, 2021 13:31
Show Gist options
  • Save itaditya/22f3225dbf1d6fbc69c7e33f991ef946 to your computer and use it in GitHub Desktop.
Save itaditya/22f3225dbf1d6fbc69c7e33f991ef946 to your computer and use it in GitHub Desktop.
sayHello is a function defined in Actor function component. Can you make App component call the sayHello function?
function Actor({ name }) {
function sayHello() {
console.log('hello', name);
}
return (
<button onClick={sayHello}>
Say Hello
</button>
);
}
export default function App() {
function handleClick() {
// call sayHello somehow.
}
return (
<div className="app">
<Actor name="Tom" />
<Actor name="Peter" />
<hr />
<button onClick={handleClick}>
I'll make Tom say hello
</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment