@@ -36,7 +36,7 @@ Hooks for ultimate flexibility as well as the new Context API for ease of use. M
3636error states, without assumptions about the shape of your data or the type of request.
3737
3838- Zero dependencies
39- - Works with any (native) Promise and the Fetch API
39+ - Works with promises, async/await and the Fetch API
4040- Choose between Render Props, Context-based helper components or the ` useAsync ` and ` useFetch ` hooks
4141- Provides convenient ` isLoading ` , ` startedAt ` and ` finishedAt ` metadata
4242- Provides ` cancel ` and ` reload ` actions
@@ -45,6 +45,7 @@ error states, without assumptions about the shape of your data or the type of re
4545- Supports [ abortable fetch] by providing an AbortController
4646- Supports optimistic updates using ` setData `
4747- Supports server-side rendering through ` initialValue `
48+ - Comes with type definitions for TypeScript
4849- Works well in React Native too!
4950
5051[ abortable fetch ] : https://developers.google.com/web/updates/2017/09/abortable-fetch
@@ -79,6 +80,7 @@ error states, without assumptions about the shape of your data or the type of re
7980 - [ Form submission] ( #form-submission )
8081 - [ Optimistic updates] ( #optimistic-updates )
8182 - [ Server-side rendering] ( #server-side-rendering )
83+ - [ Who's using React Async] ( #whos-using-react-async )
8284- [ Acknowledgements] ( #acknowledgements )
8385
8486## Rationale
@@ -135,10 +137,11 @@ core functionality from within your own function components:
135137``` js
136138import { useAsync } from " react-async"
137139
138- const loadCustomer = ({ customerId }, { signal }) =>
139- fetch (` /api/customers/${ customerId} ` , { signal })
140- .then (res => (res .ok ? res : Promise .reject (res)))
141- .then (res => res .json ())
140+ const loadCustomer = async ({ customerId }, { signal }) => {
141+ const res = await fetch (` /api/customers/${ customerId} ` , { signal })
142+ if (! res .ok ) throw new Error (res)
143+ return res .json ()
144+ }
142145
143146const MyComponent = () => {
144147 const { data , error , isLoading } = useAsync ({ promiseFn: loadCustomer, customerId: 1 })
@@ -273,7 +276,7 @@ const MyComponent = () => (
273276
274277### Options
275278
276- These can be passes in an object to ` useAsync ` , or as props to ` <Async> ` and custom instances.
279+ These can be passed in an object to ` useAsync() ` , or as props to ` <Async> ` and custom instances.
277280
278281- ` promiseFn ` Function that returns a Promise, automatically invoked.
279282- ` deferFn ` Function that returns a Promise, manually invoked with ` run ` .
@@ -306,11 +309,11 @@ to send data to the server following a user action, such as submitting a form. Y
306309` promiseFn ` to fill the form with existing data, then updating it on submit with ` deferFn ` .
307310
308311> Be aware that when using both ` promiseFn ` and ` deferFn ` , the shape of their resolved value should match, because they
309- > both update the ` data ` .
312+ > both update the same ` data ` .
310313
311314#### ` watch `
312315
313- > ` boolean | any`
316+ > ` any `
314317
315318Watches this property through ` componentDidUpdate ` and re-runs the ` promiseFn ` when the value changes, using a simple
316319reference check (` oldValue !== newValue ` ). If you need a more complex update check, use ` watchFn ` instead.
@@ -634,6 +637,12 @@ render() {
634637}
635638```
636639
640+ ## Who's using React Async
641+
642+ <a href =" https://xebia.com " ><img src =" https://user-images.githubusercontent.com/321738/52999660-a9949780-3426-11e9-9a7e-42b400f4ccbe.png " height =" 40 " alt =" Xebia " /></a > <a href =" https://intergamma.nl " ><img src =" https://user-images.githubusercontent.com/321738/52999676-b5805980-3426-11e9-899e-6c9669176df4.png " height =" 40 " alt =" Intergamma " /></a >
643+
644+ Your organization here? [ Let us know] ( https://github.com/ghengeveld/react-async/issues/22 ) you're using React Async!
645+
637646## Acknowledgements
638647
639648Versions 1.x and 2.x of ` react-async ` on npm are from a different project abandoned years ago. The original author was
0 commit comments