mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-22 03:42:14 +00:00
* 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
11 lines
294 B
JavaScript
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>;
|