Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript useLazyQuery-重新呈现问题_Javascript_React Native_Graphql_Apollo_Apollo Client - Fatal编程技术网

Javascript useLazyQuery-重新呈现问题

Javascript useLazyQuery-重新呈现问题,javascript,react-native,graphql,apollo,apollo-client,Javascript,React Native,Graphql,Apollo,Apollo Client,要求: 我想在useffect中第一次自动调用查询,然后在函数中手动调用 问题:不变性冲突:重新渲染过多 setState是导致此问题的原因,我假设。功能组件的“身体部位”在每次更改时都会运行,需要条件(或useffect挂钩)来阻止意外行为 只是不要对所有注释使用useState?你可以用f.e const allNewComments = (data && data.getPost) ? data.getPost.comments : []; 。。。如果要迭代所有新成员 如

要求:

我想在useffect中第一次自动调用查询,然后在函数中手动调用

问题:不变性冲突:重新渲染过多


setState
是导致此问题的原因,我假设。

功能组件的“身体部位”在每次更改时都会运行,需要条件(或
useffect
挂钩)来阻止意外行为

只是不要对所有注释使用
useState
?你可以用f.e

const allNewComments = (data && data.getPost) ? data.getPost.comments : [];
。。。如果要迭代
所有新成员

如果仍要使用
useState
(与
useLazyQuery
结合使用)。。。在
onCompleted
option/handler中使用它,例如:

const [getComment, { loading, data }] = useLazyQuery(getCommentsQuery, {
  variables: {
    input: {
      id: "5e5cb512e90bd40017385305",
    },
  },
  onCompleted: (data) => {setAllNewComments( data.getPost.comments )}
const [getComment, { loading, data }] = useLazyQuery(getCommentsQuery, {
  variables: {
    input: {
      id: "5e5cb512e90bd40017385305",
    },
  },
  onCompleted: (data) => {setAllNewComments( data.getPost.comments )}