MCPcopy Create free account
hub / github.com/Okabe-Rintarou-0/BookStore-Frontend / ChildComponent

Function ChildComponent

advanced_tutorial/src/cases/case3.tsx:18–36  ·  view source on GitHub ↗
(props: ChildComponentProps)

Source from the content-addressed store, hash-verified

16}
17
18const 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
38const OptimizedChildComponent = (props: ChildComponentProps) => {
39 const [propsChangeCnt, setPropsChangeCnt] = useState<number>(0);

Callers

nothing calls this directly

Calls 1

doSomethingSlowlyFunction · 0.85

Tested by

no test coverage detected