小编Eri*_*Lee的帖子

路径上的 Eslint 导入/无无关依赖项错误

我正在使用 Eslint 设置构建一个 React 应用程序。在我的应用程序中,我使用 GraphQL @apollo/client 依赖项。

当我尝试做的时候import { setContext } from '@apollo/client/link/context'

我收到一个 eslint 错误

'@apollo/client/link/context' should be listed in the project's dependencies. Run 'npm i -S @apollo/client/link/context' to add it  import/no-extraneous-dependencies
Run Code Online (Sandbox Code Playgroud)

我的 package.json 中确实有“@apollo/client”依赖项。根据 Apollo 文档,从 '@apollo/client/link/context' 导入是获取 'setContext' 的正确方法。

似乎import/no-extreaneous-dependencies无法识别“@apollo/client”的嵌套路径。

当我设置"import/no-extraneous-dependencies": 0.eslintrc.js 规则时,它会正常工作。但为了获得正确的解决方案,我假设我可能需要使用 .eslintrc.js 规则设置一些内容,而不是仅仅关闭 eslint 检查。

在这种情况下,我应该在 .eslintrc.js 中为我的规则编写哪些其他设置才能正确解决问题?

我的 package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@apollo/client": "^3.3.19",
    "@auth0/auth0-react": "^1.4.0",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10", …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint graphql apollo-client eslintrc

7
推荐指数
1
解决办法
5718
查看次数

无法使用 Google Analytics 跟踪在 React Web 应用程序上花费的时间

我已经构建了一个 React Web 应用程序,我想使用 Google Analytics 跟踪用户在我的网站上花费的时间。

目前我正在使用react-gahttps://github.com/react-ga/react-ga)作为将 Google Analytics 与 React 绑定的工具。我已经使用 Google Analytics 成功跟踪了每个页面。我可以像这样看到流量来源和概述: Google Analytics Screen shot

然而,当我检查平均数时。“花费时间”页面:Google Analytics 行为概述。我看不到任何关于 avg 的数据。所花费的时间。

以下是我在代码中设置的内容,我在 App.js 文件中初始化了 ReactGA:

应用程序.js

componentDidMount() {
    ReactGA.initialize('UA-xxxxxxx-x')
    ....
}
Run Code Online (Sandbox Code Playgroud)

我在 Routing.js 文件中跟踪了我的页面,其中我的所有反应路由器路由都在此文件中:

路由.js

componentDidMount() {
  this.props.history.listen(location => ReactGA.pageview(location.pathname))
  ...
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,这就是我为 Google Analytics 设置的全部内容react-ga

我是否错过了跟踪平均数的任何内容?在我的网站上花费的时间?

javascript google-analytics reactjs react-ga

5
推荐指数
1
解决办法
1803
查看次数