File tree Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Expand file tree Collapse file tree 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' ;
25import FCCounterUsage from '../components/fc-counter.usage' ;
6+ import FcForwardRefUsage from '../components/fc-forward-ref.usage' ;
37import 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' ;
68import UserListUsage from '../components/generic-list.usage' ;
9+ import WithConnectedCountUsage from '../hoc/with-connected-count.usage' ;
710import WithErrorBoundaryUsage from '../hoc/with-error-boundary.usage' ;
811import WithStateUsage from '../hoc/with-state.usage' ;
9- import WithConnectedCountUsage from '../hoc/with-connected-count.usage' ;
1012
1113export function Home ( ) {
1214 return (
1315 < section >
1416 < FCCounterUsage />
17+ < FcForwardRefUsage />
1518 < FCSpreadAttributesUsage />
1619 < ClassCounterUsage />
1720 < ClassCounterWithDefaultPropsUsage />
You can’t perform that action at this time.
0 commit comments