Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "restater", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Tiny hook-based state management tool for React", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -94,3 +94,3 @@ # Restater · [![NPM Version](https://img.shields.io/npm/v/restater)](https://www.npmjs.com/package/restater) ![Build Status](https://github.com/Silind-Software/restater/workflows/build/badge.svg) | ||
A store can also hold async values, and for that, we create a separate kind of store using `createAsyncStore`. | ||
Again, we provide initial values, but the store is treat these values as promises that needs to be resolved before being set. | ||
Again, we provide initial values, but the store will treat these values as promises that needs to be resolved before being set. | ||
@@ -170,15 +170,20 @@ Creating the store will work the same as before. | ||
// Result is the new username | ||
return result; | ||
}; | ||
await setUsername(getUpdatedUsername()); | ||
// Do something after update | ||
setUsername(getUpdatedUsername()); | ||
``` | ||
This will cause the `username.state` to go into `loading` in any component that is using the username from the store. | ||
Note that the `setUsername` itself returns a Promise, so we can await it and do something after the `username.state` has gone into either `completed` or `failed`. | ||
Note that the `setUsername` itself returns a Promise, so we can await it and do something after the `username.state` has gone into either `completed` or `failed`. | ||
```javascript | ||
await setUsername(getUpdatedUsername()); | ||
// Do something after the username has been updated | ||
``` | ||
### Helper functions | ||
To avoid wrapping too many providers in each other, you can use the helper function `combineProviders` which will reduce a list of providers into one. | ||
To avoid wrapping too many providers in each other, you can use the helper function `combineProviders` which will combine a list of providers into one. | ||
```javascript | ||
@@ -185,0 +190,0 @@ import { combineProviders } from 'restater'; |
21695
224