Skip to content

Latest commit

History

History
21 lines (15 loc) 路 516 Bytes

forward-ref.md

File metadata and controls

21 lines (15 loc) 路 516 Bytes

React Forward Ref

Back{: .button}

React Forward Ref lets campononts take a ref they receive and pass it further down

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>;

Reference