I am not sure what the best practice is to pass variables in refetchQueries options. In below example the variables is {id: this.props.item.id}
But passing this.props.item.id returned an error since MyComponent is not yet instantiated hence this.props is undefined.
function mapStateToProps(state) {
return {
item: state.item
};
}
MyComponent = connect(mapStateToProps, matchDispatchToProps)(
MyComponent
);
MyComponent = graphql(createItemImage, {
name: "createItemImage",
options: {
refetchQueries: [
{
query: getEntity,
variables: { id: this.props.item.id }
}
]
}
})(MyComponent);
The id value will only be available during runtime.
Thanks in advance!
This is what finally works, refer to ownProps and the order (connect statement should be after the graphql statement)
MyComponent = graphql(createItemImage, {
name: "createItemImage",
options: ownProps => ({
refetchQueries: [
{
query: getEntity,
variables: { id: ownProps.item.id }
}
]
})
})(MyComponent);
MyComponent = connect(mapStateToProps, matchDispatchToProps)(
MyComponent
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With