File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 22 * @Author : saber2pr
33 * @Date : 2019-12-06 17:41:19
44 * @Last Modified by: saber2pr
5- * @Last Modified time: 2019-12-11 21:02:47
5+ * @Last Modified time: 2019-12-13 16:38:54
66 */
77import React , { useState , useEffect , useRef } from ".."
88import ReactDOM from "../client"
@@ -20,6 +20,7 @@ import { TestUseEffect } from "./TestUseEffect"
2020import { TestForwardRef } from "./TestForwardRef"
2121import { TestContext } from "./TestContext"
2222import { TestLazy } from "./TestLazy"
23+ import { TestMemo } from "./TestMemo"
2324
2425const Store = {
2526 state : 0
@@ -57,7 +58,8 @@ const Tests = [
5758 TestUseEffect ,
5859 TestForwardRef ,
5960 TestContext ,
60- TestLazy
61+ TestLazy ,
62+ TestMemo
6163]
6264
6365const App = ( ) => {
Original file line number Diff line number Diff line change 1+ /*
2+ * @Author : saber2pr
3+ * @Date : 2019-12-13 16:38:42
4+ * @Last Modified by: saber2pr
5+ * @Last Modified time: 2019-12-13 16:55:19
6+ */
7+ import React , { useEffect , useState } from ".."
8+
9+ const Content = React . memo ( ( { content } : { content : string } ) => {
10+ useEffect ( ( ) => {
11+ console . log ( "memo" )
12+ } )
13+ return < div > { content } </ div >
14+ } )
15+
16+ const useForceUpdate = ( ) => {
17+ const [ tick , setTick ] = useState ( 0 )
18+ return ( ) => setTick ( tick + 1 )
19+ }
20+
21+ const TestMemo = ( ) => {
22+ const [ text , setText ] = useState ( "awsl" )
23+ const forceUpdate = useForceUpdate ( )
24+ return (
25+ < div >
26+ < div > TestMemo Demo</ div >
27+ < div >
28+ < Content content = { text } />
29+ </ div >
30+ < div >
31+ < button onclick = { ( ) => setText ( "xmsl" ) } > setText1</ button >
32+ < button onclick = { ( ) => setText ( "awsl" ) } > setText2</ button >
33+ </ div >
34+ < button onclick = { forceUpdate } > forceUpdate</ button >
35+ </ div >
36+ )
37+ }
38+
39+ export { TestMemo }
You can’t perform that action at this time.
0 commit comments