|
@@ -0,0 +1,32 @@
|
|
|
|
+import { useEffect, useState } from "react"
|
|
|
|
+
|
|
|
|
+const TP = (props: { children: string }) => {
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ console.log(props.children, 'mount')
|
|
|
|
+ return () => console.log(props.children, 'unmount')
|
|
|
|
+ }, [props.children])
|
|
|
|
+
|
|
|
|
+ return <p>{ props.children }</p>
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const TP1 = () => <TP children="111" />
|
|
|
|
+const TP2 = () => <TP children="222" />
|
|
|
|
+const TP3 = () => <TP children="333" />
|
|
|
|
+const TP4 = () => <TP children="444" />
|
|
|
|
+
|
|
|
|
+const Test = () => {
|
|
|
|
+ const [show, setShow] = useState(false)
|
|
|
|
+ const children = show ? [ TP1, TP2, TP3 ] : [ TP4, TP1, TP2, TP3 ]
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <>
|
|
|
|
+ <button onClick={() => setShow(show => !show)}>切换</button>
|
|
|
|
+ { show && <TP4 /> }
|
|
|
|
+ <TP1 />
|
|
|
|
+ <TP2 />
|
|
|
|
+ <TP3 />
|
|
|
|
+ </>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export default Test
|