Skip to content

Commit

Permalink
Merge pull request #155 from chaffeqa/patch-1
Browse files Browse the repository at this point in the history
Correct reducer documentation
  • Loading branch information
Sashko Stubailo authored Mar 7, 2017
2 parents 7d0ff34 + a671ed7 commit 553dd40
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions react-docs/source/cache-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mutate({

<h2 id="resultReducers">Using `reducer`</h2>

While `updateQueries` can only be used to update other queries based on the result of a mutation, the `reducer` option is a way that lets you update the query result based on any action, including results of other queries. It acts just like a Redux reducer on the non-normalized query result:
While `updateQueries` can only be used to update other queries based on the result of a mutation, the `reducer` option is a way that lets you update the query result based on any **apollo** action, including results of other queries or mutations. It acts just like a Redux reducer on the non-normalized query result:

```javascript
import update from 'immutability-helper';
Expand All @@ -367,10 +367,6 @@ const CommentsPageWithData = graphql(CommentsPageQuery, {
},
},
});
} else if (action.type === 'MY_CUSTOM_REDUX_ACTION') {
return update(previousResult, {
currentUser: { $set: null },
});
}
return previousResult;
},
Expand All @@ -379,7 +375,9 @@ const CommentsPageWithData = graphql(CommentsPageQuery, {
})(CommentsPage);
```

As you can see, the `reducer` option can be used to achieve the same goal as `updateQueries`, but it is more flexible and works with any type of action, not just mutations. For example, the query result can be updated based on another query's result, or even a simple redux action.
As you can see, the `reducer` option can be used to achieve the same goal as `updateQueries`, but it is more flexible and works with any type of **apollo** action, not just mutations. For example, the query result can be updated based on another query's result.

**Coming soon:** will be invoked on any redux action, not just apollo specific.



Expand Down

0 comments on commit 553dd40

Please sign in to comment.