使用withState更改带有useEffect的graphql useQuery查询

时间:2019-11-07 19:26:27

标签: reactjs react-hooks recompose

我发现这个问题使我成为enter link description here的一部分,但是我仍然茫然如何使用useEffect来实现它。

我想像这样设置查询变量:

  const [variables, setVariables] = React.useState(false)
  React.useEffect(() => {
    console.log(variables)
    refetch({
      userIds: variables
    });
    console.log("IN USEFEFFECT", userData)
  }, [variables]);

  const setSelectedUsers = values => {
    console.log("INITIAL DATA", userData)
    setSelectedUsersToDelete(values)
    setVariables(values.join(','))
  }

我这样编写查询:

import { graphql, compose } from 'react-apollo';
import { withState } from 'recompose';

export default compose(
    withState('isSkipRequest', 'setSkipRequest', true),
    graphql(
        gql`
        query($offset: Int, $limit: Int, $search: String, $userIds: String) {
          users(offset: $offset, limit: $limit, search: $search, userIds: $userIds) {
            id
            email
            firstName
            lastName
            phone
            email
          }
          totalUsers
        }
      `,
      {
        name: 'handleLoad',
          variables: {
            userIds: variables
          }
      }
    ),
);

我只是不确定如何将所有这些链接起来,因此我的查询变量是动态更改的?

0 个答案:

没有答案