Skip to content

Commit e474dc2

Browse files
authored
add forwardref and hoc example to ADVANCED
1 parent f52f662 commit e474dc2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ADVANCED.md

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export function inject<TProps, TInjectedKeys extends keyof TProps>(
146146
}
147147
```
148148

149+
### Using `forwardRef`
150+
151+
For "true" reusability you should also consider exposing a ref for your HOC. You can use `React.forwardRef<Ref, Props>` as documented in [the basic cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/blob/master/README.md#forwardrefcreateref), but we are interested in more real world examples. [Here is a nice example in practice](https://gist.github.com/OliverJAsh/d2f462b03b3e6c24f5588ca7915d010e) from @OliverJAsh.
152+
149153
## Render Props
150154

151155
Sometimes you will want to write a function that can take a React element or a string or something else as a prop. The best Type to use for such a situation is `React.ReactNode` which fits anywhere a normal, well, React Node would fit:

0 commit comments

Comments
 (0)