我有这个关注按钮组件,该组件运行查询以检查登录的用户是否在关注我们所在个人资料的用户。如果用户正在关注查看的用户个人资料,则in渲染一个取消关注按钮,否则将渲染一个关注按钮。我的问题是,运行突变后,我的组件不会重新加载。我试图找出一种在突变完成后重新运行查询的方法。
这是我的退货单
return (
<div>
<Query query={IS_FOLLOWING} variables={{ from: this.props.user.username, to: this.props.username }} >
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error</p>;
if (data.IsUserFollowing) return (
<Mutation mutation={UNFOLLOW_MUTATION} onCompleted={this.handleCompleted} variables={{ from: { id: this.props.user.id }, to: { id: this.props.user_id } }}>
{postMutation => <button onClick={postMutation}>Unfollow</button>}
</Mutation>
)
return (
<Mutation mutation={FOLLOW_MUTATION} onCompleted={this.handleCompleted} variables={{ from: { id: this.props.user.id }, to: { id: this.props.user_id } }}>
{postMutation => <button onClick={postMutation}>Follow</button>}
</Mutation>
)
}}
</Query >
</div>
)