(props: ChildComponentProps)
| 16 | } |
| 17 | |
| 18 | const ChildComponent = (props: ChildComponentProps) => { |
| 19 | const [propsChangeCnt, setPropsChangeCnt] = useState<number>(0); |
| 20 | useEffect(() => { |
| 21 | setPropsChangeCnt(cnt => cnt + 1); |
| 22 | }, [props.onChange]); |
| 23 | |
| 24 | const doSomethingSlowly = () => { |
| 25 | sleep(500); |
| 26 | return Math.random(); |
| 27 | }; |
| 28 | |
| 29 | const cnt = doSomethingSlowly(); |
| 30 | |
| 31 | return <Space> |
| 32 | <p>运行结果: {cnt}</p> |
| 33 | <p>Props 变更次数: {propsChangeCnt}</p> |
| 34 | <Button onClick={props.onChange}>按下按钮</Button> |
| 35 | </Space> |
| 36 | } |
| 37 | |
| 38 | const OptimizedChildComponent = (props: ChildComponentProps) => { |
| 39 | const [propsChangeCnt, setPropsChangeCnt] = useState<number>(0); |
nothing calls this directly
no test coverage detected