Answer the question
In order to leave comments, you need to log in
How to save ref correctly?
Hello, how to correctly save ref from child component to parent component's state. My problem is that it starts an endless re-render of the parent component. Here is the code: https://codesandbox.io/embed/jjorv3wz49
Answer the question
In order to leave comments, you need to log in
You don’t need to save it in state, just add a link to the class property:
class Parent extends React.Component {
childRef = React.createRef();
render() {
return <Child childRef={this.childRef} />;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question