Answers for "react forwardref"

11

react forwardref

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>;
Posted by: Guest on March-05-2020
0

send props to forwardref

<Component {...props} ref={ref} />
Posted by: Guest on April-02-2021
-1

Did you mean to use React.forwardRef()?

import {useRef} from 'react';

// hten define the ref
const inputRef = useRef(null);

// then use it in the tag
<section ref={inputRef} >...</section>
Posted by: Guest on February-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language