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.

Quick Fix command for missing React component imports does not work without React in the scope even with the new JSX factory enabled in Next.js that makes the React import unnecessary

See original GitHub issue
  • VSCode Version: 1.51.0
  • OS Version: macOS 10.15.7
  • Typescript Version: 4.0.5

Steps to Reproduce:

  1. Clone the following repository: https://github.com/ChristianIvicevic/react-jsx-factory-repro
  2. yarn install all dependencies
  3. Open the index.tsx and add the SampleComponent without automatic completion and import of the component
  4. Try to use Quick Fix on the SampleComponent to automatically add its import
  5. Only the fix to import React is available initially - apply this Quick Fix
  6. Open the Quick Fix for a second time - now you are able to add the import for the SampleComponent

Here is a gif of the differences with automatic import and with Quick Fixes:

Kapture 2020-11-09 at 02 20 10

With the newest version of Next.js it is no longer necessary to import the default export of React, thus step 5 should not appear in the first place.

Does this issue occur when all extensions are disabled?: Yes

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:45
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
rshaulcommented, Apr 13, 2021

Next.js (which is what this issue was opened about) uses "jsx": "preserve" in its tsconfig so unfortunately that PR doesn’t solve this (tested with the 4.3.0-beta release of typescript & stable VS Code).

6reactions
Hiroki111commented, Jun 28, 2021

@billyjanitsch

I believe this was fixed by #41950, which will be released in TypeScript 4.3. That PR is listed as closing #41920 which is a duplicate of this issue. (It’s phrased differently but I believe it’s the same issue.)

Unfortunately, this still persists 😦 (typescript@4.3.4)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the New JSX Transform – React Blog
Remove all unused React imports as a result of upgrading to the new JSX transform. Change all default React imports (i.e. import React...
Read more >
'React' must be in scope when using JSX ... - Stack Overflow
The import line should be: import React, { Component } from 'react';. Note the uppercase R for React.
Read more >
Migrating from Create React App - Next.js
Migrating from Create React App. This guide will help you understand how to transition from an existing non-ejected Create React App project to...
Read more >
typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ...
Read more >
The starting point for learning TypeScript
TypeScript Documentation. Get Started. Quick introductions based on your background or preference. TS for the New Programmer · TypeScript for JS ...
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