从组件prop调用方法后的react-apollo突变

时间:2019-04-17 17:51:25

标签: reactjs apollo react-apollo

我有一个从其子级调用方法的功能组件,在该方法完成其新状态var的构建后,我需要做一个突变。

我从孩子那里呼唤的方法:

doStuffWithPassedArrFromChild = (needed1, needed2){
// do a bunch of stuff with the params and create state var of filters
   this.setState{filters:{ stuff I need to keep selected checkboxes checked }}
} 

我的组件:

<FilterComponent 
   filters={this.state.filters}
   creatFinalFilters{this.doStuffWithPassedArrFromChild}
/>

但是在调用doStuffWithPassedArrFromChild之后,我需要调用一个阿波罗反应突变。

我是否用Mutation组件包装并以某种方式链接方法?

<Mutation mutation={SET_SOMETHING}>
       {mutate => (
         <FilterComponent 
          filters={this.state.filters}
          creatFinalFilters{
              this.doStuffWithPassedArrFromChild
              mutate({ variables: { this.state.filters } })

               // how do I call the above mutate?  
               //Some way of chaining? 
               //or a way inside the doSTuffWithPassedArrFromChild ?

              }
         />
       )}

一旦从子级调用createFinalFilters,并完成创建新的状态var,如何触发突变?

0 个答案:

没有答案