1

I need to figure out, is there any difference between this code?

ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById('root') ); 

And this babel configuration

{ "strictMode": true } 

If I use only just babel config with strictMode:true then no need to StrictMode component? And vice versa

3
  • No, not the same thing at all. React.StrictMode is a React component with "special behavior" for testing invariants in non-production builds, babel is a code transpiler, the strictMode being a Javascript thing. Commented Nov 20, 2021 at 9:46
  • @DrewReese okay, thanks. Write an answer, I'll accept it :) Commented Nov 20, 2021 at 9:47
  • 1
    babeljs.io/docs/en/babel-plugin-transform-strict-mode and reactjs.org/docs/strict-mode.html Commented Nov 20, 2021 at 9:49

1 Answer 1

1

StrictMode is a tool for highlighting potential problems in an application. Like Fragment, StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants.

as mentioned in the documentation

when elements wrapped inside of <React.StrictMode> they :

  • Identify components with unsafe lifecycles
  • Warn about legacy string ref API usage
  • Warn about deprecated findDOMNode usage
  • Detect unexpected side effects
  • Detect legacy context API

While the strictMode in babel is for the ES6 modules to transform. ES6 modules have an implicit strict mode. There not much resource out there for babel but that's pretty much it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.