Reputation: 503
I use shift
+ alt
+ o
to remove those unused modules I don't need anymore quite often.
It worked fine when doing so in the .tsx
file before.
But somehow VS Code removes the import React from 'react'
statement recently which didn't happen before.
Is it due to some updates of VS Code recently?
I found this setting below, not sure if it's related or not. But neither enabled and disabled status work.
Or any other reason that may cause this issue?
Upvotes: 2
Views: 2224
Reputation: 503
For some reason, we keep React 16 in the existing project.
And one viable fix is to add jsx: 'react'
to the compilerOptions
in tsconfig.json
{
"compilerOptions": {
"jsx": "react",
}
}
Ref: https://github.com/microsoft/TypeScript/issues/49486#issuecomment-1157426215
Upvotes: 0
Reputation: 74
Because the need for adding import React from 'react';
is not need with the latest react update so that it is taken out.
Upvotes: 1
Reputation: 1450
If you are using React v17 then no need to import React from 'react'
in order to write JSX. You can read more here react v17
Upvotes: 1