Up until today, whenever I requested "useState" on a new page or component for a React application, I would get the following autocomplete option:
import { useState } from "react";
As far as I can tell, this is still the correct import statement for useState. However, today, when I try to import useState, I am given two options:
import { useState } from "react/cjs/react.production.min";
import { useState } from "react/cjs/react.development";
Also, when employing useState:
const [thisVar, setThisVar] = useState(0);
VS Code used to highlight the setter, or `setThisVar’, in yellow. It no longer does this, as shown in this image. This leads me to think it is no longer recognizing the setter as a function by default. The previous code still works as intended, it’s just annoying to have to correct the import statement every time. I’m also worried that it’s part of a larger issue.
I have tried installing the extension "JavaScript and TypeScript Nightly" which seems to have had no effect on the problem. I have also tried installing the latest version of "@types/react", which similarly has not corrected the issue.
Has there been some recent change to ESLint or Prettier that would cause this? Does anyone know how to get VSCode back to working as intended?
Thanks!
2
Answers
I faced the same problem and solved it by updating vscode to the latest version.
At first, check your vscode version. I faced kind of similar problems in vscode yesterday with the latest release Version 1.94 .
However, I was not working with React.js, I was working with node.js and the Intellisense was not working properly. There was no code suggestions and code completions were not working.
A lot of other people are facing similar issues. You can check vscode github issues here.
One possible temporary workaround is: go back to previous version of VS Code.
To do that:
But going back to previous version has some caveats. Specially for security issues. So, once vscode maintainers solves this problem, update you vscode.