【发布时间】:2017-12-02 03:51:32
【问题描述】:
我有一个组件,它使用 react-apollo 装饰器语法显示 GraphQL 查询的结果。该查询接受一个参数,我想根据组件状态动态设置该参数。
考虑以下简化示例:
import * as React from ‘react’;
import { graphql } from ‘react-apollo’;
import gql from ‘graphql-tag’;
const myQuery = gql`
query($active: boolean!) {
items(active: $active) {
}
}
`;
@graphql(myQuery)
class MyQueryResultComponent extends React.Component {
public render() {
return <div>
<input type=“checkbox” /* other attributes and bindings */ />
{this.props.data.items}
<div>;
}
}
单击复选框时,我想重新提交查询,根据复选框的状态动态设置myQuery 中的active 属性。为简洁起见,我省略了复选框的处理程序和绑定,但是如何在状态更改时重新提交查询?
【问题讨论】:
标签: javascript reactjs graphql react-apollo