1SomeComponent (props) => {
2
3 useEffect( () => {
4 console.log('someProp updated');
5 }, [props.someProp])
6
7
8 return <div>Hi {props.someProp}</div>
9}
1const { useState, useEffect, useMemo } = React;
2
3function App() {
4 const [count, setCount] = useState(50);
5
6 useEffect(() => {
7 setTimeout(() => {
8 setCount(150);
9 }, 2000);
10 }, []);
11
12 return <DisplayCount count={count} />;
13}
14
15function DisplayCount(props) {
16 const count = useMemo(() => props.count > 100 ? 100 : props.count, [props.count]);
17
18 return <div> {count} </div>;
19}
20
21ReactDOM.render(<App />, document.getElementById("root"));