A
A
alex4answ2021-04-19 19:48:49
React
alex4answ, 2021-04-19 19:48:49

Why is createRef needed in class components?

Why is it needed React.createRef()in class components?

What is the essential difference between:

class MyComponent extends React.Component {
  myRef = null
  
  render() {
    return <div ref={ref => myRef = ref} />;
  }
}

and
class MyComponent extends React.Component {
  myRef = React.createRef();
  
  render() {
    return <div ref={myRef} />;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klein Maximus, 2021-04-19
@kleinmaximus

Reading the documentation - https://ru.reactjs.org/docs/react-api.html#reactcr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question