1const EnhancedTable = ({ parentCallback }) => {
2 const [count, setCount] = useState(0);
3
4 return (
5 <button onClick={() => {
6 const newValue = count + 1;
7 setCount(newValue);
8 parentCallback(newValue);
9 }}>
10 Click me {count}
11 </button>
12 )
13};
14
15class PageComponent extends React.Component {
16 callback = (count) => {
17 // do something with value in parent component, like save to state
18 }
19
20 render() {
21 return (
22 <div className="App">
23 <EnhancedTable parentCallback={this.callback} />
24 <h2>count 0</h2>
25 (count should be updated from child)
26 </div>
27 )
28 }
29}