react-redux-typescript-guide
react-redux-typescript-guide copied to clipboard
Document createRef and forwardRef usage
Fixes #72
Hey @adrienharnay. Thanks for your contribution. Could you please check the contributing.md guide.
One note, this PR doesn't fix #72 entirely, it would be great to include some React component example. Examples from react docs are preferred: https://reactjs.org/docs/forwarding-refs.html
const FancyButton = React.forwardRef((props, ref) => (
<button ref={ref} className="FancyButton">
{props.children}
</button>
));
// You can now get a ref directly to the DOM button:
const ref = React.createRef();
<FancyButton ref={ref}>Click me!</FancyButton>;
The best place to put it would be in the stateless components section:
That is not super clear how to use forwardRef with 16.8 react.
I am using const Component = (props: IProps, ref?: React.Ref<HTMLDivElement>) => {...} .