Getting a reference to third party components in React

Viewed 819

If you’re using a 3rd party component and you want to call a method of that component, how do you get a reference to it so that you can call it? React used to have a prop called where in the parent component you can call this.refs.myrefname.somemethod(), but looks like react removed the ref prop.

How can the same thing be achieved now?

1 Answers

well.. last i checked, it still works..

Edit: I have already shown the implementation here. anyways posted the code as well. So refs are still in work.

https://codesandbox.io/s/3rd-party-component-i9cbx

export default function App() {
  const textFieldRef = createRef();
  useEffect(() => {
    textFieldRef.current.value = "Value";
    textFieldRef.current.focus();
  }, [textFieldRef]);
  return <TextField inputRef={textFieldRef} />;
}
Related