title: import * as React from 'react'; vs import React from 'react';
body: <p>I've noticed that <code>React</code> can be imported like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import * as React from 'react';
  </code></pre>
  
  <p>...or like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import React from 'react';
  </code></pre>
  
  <hr>
  
  <p>The first imports everything in the <code>react</code> module (see: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_an_entire_module&#39;s_contents" rel="noreferrer">Import an entire module's contents</a>)</p>
  
  <p>The second imports only the <code>default</code> module export (see: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Importing_defaults" rel="noreferrer">Importing defaults</a>)</p>
  
  <hr>
  
  <p>It seems like the two approaches are different and fundamentally incompatible.</p>
  
  <p>Why do they both work?</p>
  
  <hr>
  
  <p>Please reference the source code and explain the mechanism...I'm interested in understanding how this works.</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>This is <strong>not</strong> a duplicate of <a href="https://stackoverflow.com/questions/54585763/what-is-the-difference-between-import-as-react-from-react-vs-import-react-fr">What is the difference between import * as react from &#39;react&#39; vs import react from &#39;react&#39;</a> </p>
  
  <p>That question was answered with general ES6 module information.</p>
  
  <p>I am asking about the mechanism that makes the <code>react</code> module work like this.  It seems to be related to "hacky" export mechanism <a href="https://github.com/facebook/react/blob/56035dac645af75c1a8aa8deba2bcf89b14a5aa4/packages/react/index.js#L14-L16" rel="noreferrer">in the source here</a> but it's not clear how that enables both importing the <strong>entire</strong> module and just the <strong>default</strong> export into <code>React</code> and having both of those approaches work with transpiling JSX, etc.</p>