A
A
Artur Kudashev2019-03-22 13:16:23
JavaScript
Artur Kudashev, 2019-03-22 13:16:23

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

1 answer(s)
A
Anton Spirin, 2019-03-22
@archi_kud

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 question

Ask a Question

731 491 924 answers to any question