【发布时间】:2017-04-04 16:01:45
【问题描述】:
当我尝试设置变量时,组件仅在获取完成后更新。这是一个示例代码。
class RelayExample extends React.Component {
setVars() {
this.props.relay.setVariables({id: '2'});
};
render() {
console.log(this.props.relay.pendingVariables);
return (
<div>
<button onClick={this.setVars.bind(this)}>set variable</button>
</div>
);
}
}
RelayExample = Relay.createContainer(RelayExample, {
initialVariables: {
id: '1'
},
fragments: {
userStore: ()=> {
return Relay.QL`
fragment on userStore {
user(id:$id){
email
}
}
`;
}
}
});
ReactDOM.render(
<Relay.RootContainer Component={RelayExample} route={new TestQuery()}/>,
document.getElementById('app')
);
即使我在 setVariables 函数之后立即使用 forceUpdate,我也会得到类似的结果。
setVars() {
this.props.relay.setVariables({id: '2'});
this.forceUpdate();
};
【问题讨论】:
-
环境为Relay.Store
标签: javascript reactjs graphql relayjs