te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - VSCode does not auto-import from "react" in Next.js projects - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VSCode does not auto-import from "react" in Next.js projects - Stack Overflow

programmeradmin3浏览0评论

* This is not a duplicate of this question; the accepted answer there is made for TypeScript and doesn't seem to work for JavaScript.

I am working on a Next.js project in Visual Studio Code, and when trying to auto-import anything from "react", the only auto-import suggestions e from "react.production.min" and "react.development".

I can manually import from "react", but even when I already have an import { ... } from "react" statement in the file, it still doesn't show up in the auto-import suggestions, and manually importing every hook I use can get quite tedious.

Is there a way to fix this?

* This is not a duplicate of this question; the accepted answer there is made for TypeScript and doesn't seem to work for JavaScript.

I am working on a Next.js project in Visual Studio Code, and when trying to auto-import anything from "react", the only auto-import suggestions e from "react.production.min" and "react.development".

I can manually import from "react", but even when I already have an import { ... } from "react" statement in the file, it still doesn't show up in the auto-import suggestions, and manually importing every hook I use can get quite tedious.

Is there a way to fix this?

Share Improve this question asked Mar 28, 2022 at 14:57 Leo AsoLeo Aso 12.5k4 gold badges27 silver badges50 bronze badges 1
  • 1 I have same issue for a few days now. Please tell me if you found something. – Vivek Makwana Commented Apr 7, 2022 at 18:41
Add a ment  | 

8 Answers 8

Reset to default 6

For me, installing @types/react fixes this problem.

From the top note on the original post, I'm assuming the original poster is using Javascript and not Typescript. If so, adding a jsconfig.json file to my project root and using these settings worked for me:

{
  "pilerOptions": {
    "baseUrl": ".",
    "checkJs": true,
    "jsx": "preserve"
  }
}

I have experienced same problem in OS MS Windows 10 on VS Code for React-18 Development. Auto Import Libraray works sometime but sometime not. I checked my Settings all good but still not working

finally i figured out When i used to open VS using Command-line Like DOS or Windows Power Shell some of intellisense features does not works like Auto import Libraries.

So if we open VS code with GUI like go to project directory and Right Click on white area hit the option Open VS here

Using this approach Everythings works perfectely Fine

Hopefully this will helpful for someone

If you are using typeScript then just need to add below single line code in next-env.d.ts

/// <reference types="@types/react" />

It's 2023 and I faced a similar issue. I'm not an expert but after hours of finding the cause, this worked for me:

Remove the following line from tsconfig.json

"exclude": ["node_modules"]

It is 2023. Check your tsconfig.json. There is must be this line:

"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.js", "**/*.jsx"],

check that resolutions are correct.

In my case, I just removed(not disabled!!!) the Prettier ESLint extension from the VS extensions, and then I opened the VS code settings.json file. This time I was able to see the wrong formats removed/mutated them and then saved the json file and now everything is working properly again. The first time that I opened the settings file, The Prettier ESLint extiontion prevented from seeing the wrong settings, and also when I wanted to save something I had an infinite loading for saving the file by the Prettier ESLint and have no idea why. I also didn't have a .vscode folder in my Next.js project!

Just to clarify and since I can't ment yet, I've also been able to resolve the issue with a React JavaScript (not TypeScript) app by installing the react types package (I installed globally) by executing the following:

npm i @types/react -g

Now when I start typing a hook like useState for example, I get a list of proper suggestions. list of React suggestions

As to why this problem may be happening, this is from the VSCode JavaScript documentation:

IntelliSense for JavaScript libraries and frameworks is powered by TypeScript type declaration (typings) files. Type declaration files are written in TypeScript so they can express the data types of parameters and functions, allowing VS Code to provide a rich IntelliSense experience in a performant manner.

VSCode JavaScript documentation

So it makes sense that if, for whatever reason, the types for React have not been installed, they would need to be.

发布评论

评论列表(0)

  1. 暂无评论