VSCode auto import React built-in hooks like useState, useEffect
Asked Answered
B

2

10

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

Bathilda answered 19/2, 2020 at 15:8 Comment(4)
I've been using this extension for that. marketplace.visualstudio.com/items?itemName=steoates.autoimportMulct
when i define one of each hooks, other hooks can add but when was not hook imported not work.Certain
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.Bathilda
I use a mix of JS and TS and I found marketplace.visualstudio.com/…. I can confirm it works with JSX useState.Wallflower
M
1

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
}
Midkiff answered 30/6, 2023 at 1:19 Comment(0)
K
1

Sometimes, extensions interfere with the functionality. With me, Vetur(Vue extension) was interfering with the React auto imports. I had to disable, and restart the VS Code. Now I can auto import from React. I enabled the Vetur again and restarted VS Code. Both Vue and React is working fine.

In the end, check if you are able to see the issue with some extension.

Klepht answered 15/10, 2023 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.