Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Update examples documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Feb 8, 2018
1 parent aaaf25d commit 9704d79
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
61 changes: 58 additions & 3 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,74 @@ Requests with the headers `POST`, `PUT`, `PATCH`, or `DELETE` are lazy
by default. This example demonstrates how these sorts of requests are
typically used in your application.

### Fetch Composer
### Multiple Requests

To run this example:

```
git clone https://github.com/jmeas/react-request.git
cd react-request/examples/fetch-composer
cd react-request/examples/multiple-requests
npm install
npm start
open http://localhost:3000/
```

Sometimes, you will need access to multiple requests at the same time. This
example demonstrates using the Fetch Composer to do that.
example demonstrates using the [React Composer](https://github.com/jmeas/react-composer)
library to do that.

### Request Deduplication

To run this example:

```
git clone https://github.com/jmeas/react-request.git
cd react-request/examples/request-deduplication
npm install
npm start
open http://localhost:3000/
```

This example demonstrates how many requests of the same kind are deduplicated by default.

### Response Caching

To run this example:

```
git clone https://github.com/jmeas/react-request.git
cd react-request/examples/response-caching
npm install
npm start
open http://localhost:3000/
```

Response caching comes built into React Request. This example shows the default
`fetchPolicy` that returns data from the cache when it is available, rather than
making a second request.

### Fetch Components

To run this example:

```
git clone https://github.com/jmeas/react-request.git
cd react-request/examples/fetch-components
npm install
npm start
open http://localhost:3000/
```

Often times, configuring HTTP requests requires, well, a lot of configuration, such as headers,
the URL, and the cache policy.

Rather than repeating this throughout your app, you can clean things up by creating "fetch components,"
an organizational strategy where the `<Fetch/>` components themselves are placed into standalone files.
1 change: 1 addition & 0 deletions examples/fetch-components/src/fetch-components/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Fetch } from 'react-request';
//
// In the case of this simple "post" resource, all that is needed is an ID (and
// children, since Fetch is a render prop component)

export function ReadPost({ postId, children }) {
return (
<Fetch
Expand Down

0 comments on commit 9704d79

Please sign in to comment.