我如何将状态作为 graqh ql 查询的变量 (Apollo)

How do i have a state as a variable for a graqh ql query (Apollo)

所以我想做的是将状态作为我的查询的变量,以便从 graphQl.The 中检索数据 我面临的问题是,因为它不从那里读取组件状态.

我该怎么做?

class usersScreen extends Component {

  constructor(props) {
    super(props);
    var white = 'sdfss';
    console.log(props)
    this.animatedValue = new Animated.Value(0)
    this.state = {
        active : true,
        clientId: "5acc83c4658e6c2c70b3fe1d"
    };
  };

 }
 export default graphql(GET_CLIENT_USERS, {
    options:(state) => (console.log(state),{
    variables:{
        clientId:this.state.clientId}})
 })(usersScreen);

例如,您可以在组件中使用 refetch 来传递 componentDidMount 中的变量,而不是将它们作为选项传递:

componentDidMount() {
   this.props.data.refetch({clientId:this.state.clientId})
 }

将渲染逻辑移动到新组件的另一个选项 ConnectecUsersScreen 并且在 usersScreen 的渲染中,您可以将状态作为 porp 传递:

render() {
    <ConnectecUsersScreen clientId={this.state.clientId} />
  }

现在您可以将 ConnectecUsersScreen 传递给 graphql,您将可以使用 clientId 作为道具。

使用屏幕道具将 clientId 传递到我的堆栈导航下的所有屏幕。

render() {
  <ConnectecUsersScreen screenProps={clientId:this.state.clientId} />
 }