Reactjs 警告:React Hook Useffect缺少依赖项

Reactjs 警告:React Hook Useffect缺少依赖项,reactjs,react-hooks,Reactjs,React Hooks,如果有人能帮忙的话,我想摆脱这个警告 React Hook has a missing dependency 'client' either include or remove it 当我将client传递给hook第二个参数(数组)时,它开始无限循环,当我移除数组时也是如此,下面是我的代码: `const [products, setProducts] = useState({}) const client = createClient({ // This is the sp

如果有人能帮忙的话,我想摆脱这个警告

React Hook has a missing dependency 'client' either include or remove it
当我将
client
传递给hook第二个参数(数组)时,它开始无限循环,当我移除数组时也是如此,下面是我的代码:

 `const [products, setProducts] = useState({})

  const client = createClient({
    // This is the space ID. A space is like a project folder in 
       Contentful terms
    space: "lku7p...spaceID",
    // This is the access token for this space. Normally you get both 
       ID and the token in the Contentful web app
    accessToken: "6uTK1K_DfE5uAn4.....my Key"
  })`

useEffect(()=>{
   client.getEntries()
    .then((res) => {
    let result = res.items
    result = result.map(item=>{
        const id = item.sys.id
    return {id}
    })
    setProduct(result)
},[])

包括依赖项并使用条件测试来运行
客户机
代码,或者不包含依赖项并禁用该行的eslint规则,并注释原因。当此效果运行时,更新客户机是什么?大概是
setProduct
?什么是
client
?当
client.getEntries()
运行时,为什么
client
会发生变化,从而重新触发
useffect
?请查看将HTTP调用抽象为挂钩的简单方法。请共享完整组件。我们需要知道客户端来自何处,才能知道你的钩子被触发的原因。我已经更新了代码并解释了客户端来自何处,