Files
react.dev/examples/reference-react-forward-ref.js
Lucas Duailibe dab9b8b2fd Add 'visual components' use case for forwarding refs (#798)
* Add 'visual components' use case for forwarding refs

* Rearrange "forwarding refs" to focus on simple use case

* Minor wording nits to 2018-03-29-react-v-16-3.md

* Minor wording nits to forwarding-refs.md

* Add more info to the forwardRef reference doc

* Minor wording nits to reference-react.md
2018-04-13 17:23:19 +01:00

11 lines
294 B
JavaScript

// highlight-range{1-2}
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>;