小编Dak*_*ksh的帖子

使用useEffect React Hook时如何解决缺少依赖项警告?

使用React 16.8.6(在以前的版本16.8.3中很好),当我尝试防止在获取请求上发生无限循环时,出现此错误

./src/components/BusinessesList.js
Line 51:  React Hook useEffect has a missing dependency: 'fetchBusinesses'.
Either include it or remove the dependency array  react-hooks/exhaustive-deps
Run Code Online (Sandbox Code Playgroud)

我一直找不到停止无限循环的解决方案。我想远离使用useReducer()。我确实在https://github.com/facebook/react/issues/14920找到了这个讨论,在这里可能的解决方案是You can always // eslint-disable-next-line react-hooks/exhaustive-deps if you think you know what you're doing.我不确定自己在做什么,所以我还没有尝试实现它。

我有这个当前设置,React hook useEffect永远/无限循环连续运行,唯一的注释是useCallback()我不熟悉的。

我目前的使用方式useEffect()(类似于,我一开始只想运行一次componentDidMount()

useEffect(() => {
    fetchBusinesses();
  }, []);
Run Code Online (Sandbox Code Playgroud)
const fetchBusinesses = () => {
    return fetch("theURL", {method: "GET"}
    )
      .then(res => normalizeResponseErrors(res))
      .then(res => {
        return res.json();
      }) …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint create-react-app react-hooks

58
推荐指数
12
解决办法
5万
查看次数

如何在 Gatsby.JS 项目中从索引页面重定向到以编程方式生成的路由

我想将索引重新路由//bloggatsby 项目中。/blog路由页面是在gatsby-node.js文件中生成的。

我尝试的是Redirect从返回@reach-routerIndex组件内部和内部导入,Redirect to='/blog'但这会导致Uncaught RedirectRequest错误。

index.js文件:

import React from 'react'
import { Redirect } from '@reach/router'


class BlogIndex extends React.Component {
  render() {
    return (
      <Redirect to={`/blog`} />
    )
  }
}

export default BlogIndex
Run Code Online (Sandbox Code Playgroud)

错误

gatsby reach-router

7
推荐指数
2
解决办法
5566
查看次数

如何在GoLang中创建可以容纳多种数据类型的数组?

在声明数组或切片时,我需要指定要存储在数组或列表中的数据类型

如何制作可以容纳多种类型数据的数组?

arrays go

3
推荐指数
1
解决办法
604
查看次数