StrictMode: Warning about legacy string ref API usage

Warning about legacy string ref API usage

//object ref API for managing refs

class MyComponent extends React.Component {
  constructor(props) {
    super(props);

    this.inputRef = React.createRef();
  }

  render() {
    return <input type="text" ref={this.inputRef} />;
  }

  componentDidMount() {
    this.inputRef.current.focus();
  }
}

Since object refs were largely added as a replacement for string refs, strict mode now warns about usage of string refs.

Related concepts

Warning about legacy string ref API usage

StrictMode: Warning about legacy string ref API usage — Structure map

Clickable & Draggable!

StrictMode: Warning about legacy string ref API usage — Related pages: