File tree 4 files changed +43
-4
lines changed
4 files changed +43
-4
lines changed Original file line number Diff line number Diff line change
1
+ Usage:
2
+ ``` jsx { "filePath": "./fc-forward-ref.usage.tsx" }
3
+ ```
4
+
5
+ Usage Demo:
6
+ ``` jsx
7
+ const Demo = require (' ./fc-forward-ref.usage' ).default ;
8
+ < Demo / >
9
+ ```
10
+
11
+ [ ⇦ back to guide] ( https://github.com/piotrwitek/react-redux-typescript-guide#--fc-counter )
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export type FancyButtonProps = {
4
+ className ?: string ;
5
+ children ?: React . ReactNode ;
6
+ } & React . ButtonHTMLAttributes < HTMLButtonElement > ;
7
+
8
+ // using function DevTools will show "ForwardRef(FancyButton)" instead of just "ForwardRef"
9
+ export const FancyButton = React . forwardRef <
10
+ HTMLButtonElement ,
11
+ FancyButtonProps
12
+ > ( function FancyButton ( props , ref ) {
13
+ return (
14
+ < button ref = { ref } className = "FancyButton" { ...props } >
15
+ { props . children }
16
+ </ button >
17
+ ) ;
18
+ } ) ;
19
+
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ import { FancyButton } from '.' ;
4
+
5
+ const ref = React . createRef < HTMLButtonElement > ( ) ;
6
+ export default ( ) => < FancyButton ref = { ref } > Click me!</ FancyButton > ;
Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import React from 'react' ;
2
+
3
+ import ClassCounterWithDefaultPropsUsage from '../components/class-counter-with-default-props.usage' ;
4
+ import ClassCounterUsage from '../components/class-counter.usage' ;
2
5
import FCCounterUsage from '../components/fc-counter.usage' ;
6
+ import FcForwardRefUsage from '../components/fc-forward-ref.usage' ;
3
7
import FCSpreadAttributesUsage from '../components/fc-spread-attributes.usage' ;
4
- import ClassCounterUsage from '../components/class-counter.usage' ;
5
- import ClassCounterWithDefaultPropsUsage from '../components/class-counter-with-default-props.usage' ;
6
8
import UserListUsage from '../components/generic-list.usage' ;
9
+ import WithConnectedCountUsage from '../hoc/with-connected-count.usage' ;
7
10
import WithErrorBoundaryUsage from '../hoc/with-error-boundary.usage' ;
8
11
import WithStateUsage from '../hoc/with-state.usage' ;
9
- import WithConnectedCountUsage from '../hoc/with-connected-count.usage' ;
10
12
11
13
export function Home ( ) {
12
14
return (
13
15
< section >
14
16
< FCCounterUsage />
17
+ < FcForwardRefUsage />
15
18
< FCSpreadAttributesUsage />
16
19
< ClassCounterUsage />
17
20
< ClassCounterWithDefaultPropsUsage />
You can’t perform that action at this time.
0 commit comments