7

In VSCode, how can I get auto import suggestions for React built-in hooks, like useState, useEffect, etc?

Just like what we get in CodeSandbox:

enter image description here

Enabled extensions (maybe there is some conflict between them, though I'm not getting any errors):

enter image description here

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
  • when i define one of each hooks, other hooks can add but when was not hook imported not work. – Mohmmad Ebrahimi Aval Apr 12 '22 at 18:53
  • Not sure what I did to fix it. But maybe I didn't have `"@types/react" and "@types/react-dom"` installed back then. You should install those. – cbdeveloper Apr 13 '22 at 05:01
  • I've been using this extension for that. https://marketplace.visualstudio.com/items?itemName=steoates.autoimport – Gene Sy Feb 19 '20 at 15:10
  • I use a mix of JS and TS and I found https://marketplace.visualstudio.com/items?itemName=NuclleaR.vscode-extension-auto-import. I can confirm it works with JSX useState. – Elijah May 20 '23 at 17:00

1 Answers1

0

So, one thing you can do is try updating your local settings file:

inside your project directory:

<project>/.vscode/settings.json

{
  // other vscode settings specific to this project...
  "typescript.suggest.autoImports": true, // or
  "javascript.suggest.autoImports": true
}
Daltron
  • 1,729
  • 3
  • 20
  • 37