File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
apps/react-hook-tracer-demo/src Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import * as contextDemo from './demos/ContextDemo'
5
5
import * as demo from './demos/Demo'
6
6
import * as counter from './demos/Counter'
7
7
import * as reducer from './demos/Reducer'
8
+ import * as domRef from './demos/DomRef'
8
9
import { ItemSelector } from './ItemSelector'
9
10
10
11
import './App.css'
@@ -14,6 +15,7 @@ const demoComponents = [
14
15
{ label : 'Context' , component : contextDemo . Demo } ,
15
16
{ label : 'Counter' , component : counter . Demo } ,
16
17
{ label : 'Reducer' , component : reducer . Demo } ,
18
+ { label : 'DOM ref' , component : domRef . Demo } ,
17
19
]
18
20
19
21
const sessionStorageKeyBase = '@@react-hook-tracer-demo--persistent-state:'
Original file line number Diff line number Diff line change
1
+ .parent ,
2
+ .child {
3
+ align-self : center;
4
+ display : flex;
5
+ flex-direction : column;
6
+ align-items : center;
7
+ padding : 4px 10px 4px 10px ;
8
+ border-radius : 10px ;
9
+ }
10
+
11
+ .parent .trace-panel ,
12
+ .child .trace-panel {
13
+ align-self : inherit;
14
+ }
15
+
16
+ .parent {
17
+ background-color : # ddd ;
18
+ }
19
+
20
+ .parent input {
21
+ margin-top : 4px ;
22
+ }
23
+
24
+ .child {
25
+ margin-top : 6px ;
26
+ background-color : # eee ;
27
+ }
28
+
29
+ .child input {
30
+ margin-top : 4px ;
31
+ margin-bottom : 6px ;
32
+ }
Original file line number Diff line number Diff line change
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+ import { forwardRef } from 'react'
3
+ import { useRef , useTracer } from 'react-hook-tracer'
4
+
5
+ import './DomRef.css'
6
+
7
+ export const Demo = ( ) => < Parent />
8
+
9
+ const Parent = ( ) => {
10
+ const { TracePanel } = useTracer ( )
11
+ const ref = useRef < HTMLInputElement > ( null )
12
+ return (
13
+ < div className = "parent" >
14
+ < TracePanel />
15
+ < input type = "button" value = "Focus on child text field" onClick = { ( ) => ref . current ?. focus ( ) } />
16
+ < Child ref = { ref } />
17
+ </ div >
18
+ )
19
+ }
20
+
21
+ const Child = forwardRef < HTMLInputElement > ( ( _ , ref ) => {
22
+ const { TracePanel } = useTracer ( )
23
+ return (
24
+ < div className = "child" >
25
+ < input type = "text" ref = { ref } />
26
+ < TracePanel />
27
+ </ div >
28
+ )
29
+ } )
30
+
31
+ Child . displayName = 'Child'
You can’t perform that action at this time.
0 commit comments