<div id="root">
</div>
console.clear();
const Child = ({ count, getData }) => {
React.useEffect(() => {
getData()
}, [ getData ]);
return (
<div>
{count}
</div>
)
}
const App = () => {
const [count, setCount] = React.useState(0);
const getData = React.useCallback(() => {
setTimeout(() => {
setCount((pre) => pre + 1)
}, 2000);
}, [])
return (
<div>
<Child count={count} getData={getData} />
</div>
)
}
const root = ReactDOM.createRoot(document.querySelector('#root'));
root.render(<App />);
View Compiled
This Pen doesn't use any external CSS resources.