question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move to new React imports (import * as React from 'react';)

See original GitHub issue

In 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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kumar303commented, Jan 30, 2018

Aha, it was indeed all Flow related! Sorry for the confusion. I remember now. The reason is that we sometimes access React.Node or React.ChildrenArray in our Flow definitions. These are in https://flow.org/en/docs/react/types/ so you’d need to use import * as React to reference them or import them explicitly (which could be tricky).

1reaction
kumar303commented, Jan 30, 2018

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 the import * as React approach means that nothing will break so it seems like a good pattern to switch to.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found