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.

React.lazy with dynamic import should be printed in the same way

See original GitHub issue

Prettier 1.14.3 Playground link

--parser babylon
--print-width 50

Input:

import Home from './Home'
import SomeLongLongComponent from './SomeLongLongComponent'

const Home = React.lazy(() => import('./Home'))
const SomeLongLongComponent = React.lazy(() => import('./SomeLongLongComponent'))

Output:

import Home from "./Home";
import SomeLongLongComponent from "./SomeLongLongComponent";

const Home = React.lazy(() => import("./Home"));
const SomeLongLongComponent = React.lazy(() =>
  import("./SomeLongLongComponent")
);

Expected behavior:

import Home from "./Home";
import SomeLongLongComponent from "./SomeLongLongComponent";

const Home = React.lazy(() => import("./Home"));
const SomeLongLongComponent = React.lazy(() => import("./SomeLongLongComponent"));

or

import Home from "./Home";
import SomeLongLongComponent from "./SomeLongLongComponent";

const Home = React.lazy(() =>
  import("./Home")
);
const SomeLongLongComponent = React.lazy(() =>
  import("./SomeLongLongComponent")
);

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
duailibecommented, Dec 4, 2018

I can’t see the need for this.

I don’t think we should special case React.lazy at all, but we could change the formatting of a lambda if the body is an import() expression. I don’t see why though…

0reactions
hawkrivescommented, Dec 4, 2018

Yeah, agreed - it is a bit of a stretch.

I haven’t done a lot of work with dynamic imports yet, so I don’t have a very strong opinion at this time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically Importing Components with React.lazy
In React, dynamically importing a component is easy—you invoke React.lazy with the standard dynamic import syntax and specify a fallback UI.
Read more >
Code-Splitting - React
The React.lazy function lets you render a dynamic import as a regular component. Before: import OtherComponent from './OtherComponent';. After:.
Read more >
Understanding Dynamic imports, Lazy and Suspense using ...
We have a function called, importDemo which takes a file as an argument. This file argument represents the selected demo based on the...
Read more >
React Lazy Loading: The Best Complete Guide - CopyCat Blog
`React lazy()` makes it easy to render react components that are imported using the dynamic import() technique. The components are rendered as ......
Read more >
Mixing dynamic imports with if conditions - Stack Overflow
The smiley will only import if it is being rendered. // parent.js import * as React from 'react' const SmileyFace = React.lazy(() ...
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