1const { useState } = React;
2
3function PageComponent() {
4 const [count, setCount] = useState(0);
5 const increment = () => {
6 setCount(count + 1)
7 }
8
9 return (
10 <div className="App">
11 <ChildComponent onClick={increment} count={count} />
12 <h2>count {count}</h2>
13 (count should be updated from child)
14 </div>
15 );
16}
17
18const ChildComponent = ({ onClick, count }) => {
19 return (
20 <button onClick={onClick}>
21 Click me {count}
22 </button>
23 )
24};
25
26ReactDOM.render(<PageComponent />, document.getElementById("root"));