skip to Main Content

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


  1. I faced the same problem and solved it by updating vscode to the latest version.

    Login or Signup to reply.
  2. 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:

    1. Go to the first link you I provided
    2. Download a previous version of vscode.
    3. Uninstall current vscode.
    4. Disconnect your internet connection to prevent it from auto-updating.
    5. Intall the previous version of vscode you just downloaded.
    6. Disable auto update.

    But going back to previous version has some caveats. Specially for security issues. So, once vscode maintainers solves this problem, update you vscode.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search