Move to new React imports (import * as React from 'react';)
See original GitHub issueIn the future we should import React as import * as React from 'react';
instead of our previous style (import React from 'react';
). This should be doable as a simple find + replace 😄
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Importing and Exporting Components - React Docs
You can move a component in three steps: Make a new JS file to put the components in. Export your function component from...
Read more >import * as React from 'react'; vs import React from 'react'
It seems to be related to "hacky" export mechanism in the source here but it's not clear how that enables both importing the...
Read more >You no longer need to import React from 'react'
If you use React, import React from 'react' is the first thing that you write in your code but if you have created...
Read more >Importing Components in React From Other Files - Upmostly
Functional Component Imports in React ... In React, importing is the same as in vanilla JavaScript. Let's do a similar example to the...
Read more >Migrating your React Router App to Remix
import * as ReactDOM from "react-dom"; import App from "./App"; ReactDOM.render(<App />, document.getElementById("app"));.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Aha, it was indeed all Flow related! Sorry for the confusion. I remember now. The reason is that we sometimes access
React.Node
orReact.ChildrenArray
in our Flow definitions. These are in https://flow.org/en/docs/react/types/ so you’d need to useimport * as React
to reference them or import them explicitly (which could be tricky).Something changed in React 16 where
import React from 'react'
no longer works for referencing some things. I looked in their changelog but I couldn’t find a specific mention, I just know that we had to update a fair bit of imports to get some components to work. We didn’t have to update all of them but theimport * as React
approach means that nothing will break so it seems like a good pattern to switch to.