diff --git a/playground/src/components/fc-forward-ref.md b/playground/src/components/fc-forward-ref.md new file mode 100644 index 0000000..8833ffb --- /dev/null +++ b/playground/src/components/fc-forward-ref.md @@ -0,0 +1,11 @@ +Usage: +```jsx { "filePath": "./fc-forward-ref.usage.tsx" } +``` + +Usage Demo: +```jsx +const Demo = require('./fc-forward-ref.usage').default; + +``` + +[⇦ back to guide](https://github.com/piotrwitek/react-redux-typescript-guide#--fc-counter) diff --git a/playground/src/components/fc-forward-ref.tsx b/playground/src/components/fc-forward-ref.tsx new file mode 100644 index 0000000..6c75802 --- /dev/null +++ b/playground/src/components/fc-forward-ref.tsx @@ -0,0 +1,19 @@ +import React from 'react'; + +export type FancyButtonProps = { + className?: string; + children?: React.ReactNode; +} & React.ButtonHTMLAttributes; + +// using function DevTools will show "ForwardRef(FancyButton)" instead of just "ForwardRef" +export const FancyButton = React.forwardRef< + HTMLButtonElement, + FancyButtonProps +>(function FancyButton(props, ref) { + return ( + + ); +}); + diff --git a/playground/src/components/fc-forward-ref.usage.tsx b/playground/src/components/fc-forward-ref.usage.tsx new file mode 100644 index 0000000..d5f6dbd --- /dev/null +++ b/playground/src/components/fc-forward-ref.usage.tsx @@ -0,0 +1,6 @@ +import React from 'react'; + +import { FancyButton } from '.'; + +const ref = React.createRef(); +export default () => Click me!; diff --git a/playground/src/routes/home.tsx b/playground/src/routes/home.tsx index 87c88a6..59779d9 100644 --- a/playground/src/routes/home.tsx +++ b/playground/src/routes/home.tsx @@ -1,17 +1,20 @@ -import React from 'react' +import React from 'react'; + +import ClassCounterWithDefaultPropsUsage from '../components/class-counter-with-default-props.usage'; +import ClassCounterUsage from '../components/class-counter.usage'; import FCCounterUsage from '../components/fc-counter.usage'; +import FcForwardRefUsage from '../components/fc-forward-ref.usage'; import FCSpreadAttributesUsage from '../components/fc-spread-attributes.usage'; -import ClassCounterUsage from '../components/class-counter.usage'; -import ClassCounterWithDefaultPropsUsage from '../components/class-counter-with-default-props.usage'; import UserListUsage from '../components/generic-list.usage'; +import WithConnectedCountUsage from '../hoc/with-connected-count.usage'; import WithErrorBoundaryUsage from '../hoc/with-error-boundary.usage'; import WithStateUsage from '../hoc/with-state.usage'; -import WithConnectedCountUsage from '../hoc/with-connected-count.usage'; export function Home() { return (
+