From 78da466af8003da35cf900337e8d277f6e7c72d3 Mon Sep 17 00:00:00 2001 From: markbello Date: Tue, 7 Apr 2020 14:05:28 -0400 Subject: [PATCH] feat(readme): document how to use query params --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index fb64b90..4ebd40d 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,31 @@ These actions allow you to remove the associated data to a resource or collectio ### Query opts iguazu-rest allows you to specify your query parameters as part of the opts passed to fetch. If they are used to filter a collection, make sure they are passed in this way instead of adding them directly to the url because it is necessary for proper caching. All of the resources get normalized, so iguazu-rest needs to a way to cache which resources came back for a set of query parameters. +```jsx +// Articles.jsx +import { connectAsync } from 'iguazu'; +import { queryCollection } from 'iguazu-rest'; + +const Articles = ({ articles }) => ( +
+ {articles.map((article) =>
)} +
+); + +function loadDataAsProps({ store: { dispatch } }) { + return { + articles: () => dispatch(queryCollection({ + resource: 'articles', + opts: { + query: { limit: 10, sortBy: 'title' }, + }, + })), + }; +} + +export default connectAsync({ loadDataAsProps })(Articles); +``` + ## 🏆 Contributing We welcome Your interest in the American Express Open Source Community on Github.