gpt4 book ai didi

reactjs - 无法解析符号 useParams

转载 作者:行者123 更新时间:2023-12-03 18:25:07 26 4
gpt4 key购买 nike

我正在创建一个使用 WebStorm 使用react的应用程序。我正在尝试使用 react-router-dom useParams。我有 react-router-dom 5.1.2 作为依赖项,但 useParams 在 import 语句中是灰色的。当我将鼠标悬停在 useParams 上时,它会显示“无法解析符号 useParams”。我也在尝试导入 Switch,但我收到了类似的消息“无法解析符号 Switch”。更不寻常的是 Link 是从 react-router-dom 导入的。

enter image description here enter image description here enter image description here

最佳答案

node_modules/react-router-dom/esm/react-router-dom.js转口Switch , Root , useParams来自 react-router .但后者并未在您的 package.json 中列为直接依赖项。因此被排除在索引之外。
您可以通过选择 取消排除它将目录标记为/不排除 来自 node_modules/react-router右键菜单:

enter image description here

但我强烈建议为包安装 Typescript stub 以获得更好的完成/类型提示:将光标放在 "react-router-dom" 上在导入语句中,点击 Alt+Enter ,选择 安装 TypeScript 定义以获得更好的类型信息

enter image description here

https://www.jetbrains.com/help/webstorm/2019.3/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files

关于reactjs - 无法解析符号 useParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60424238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com