Skip to content

Commit

Permalink
more clarity in README + Vanilla.js example
Browse files Browse the repository at this point in the history
  • Loading branch information
MZanggl committed Jun 26, 2020
1 parent aaf2a9d commit eb998b3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Easily manage promises in reactive JavaScript libraries and frameworks such as R
- [Alpine.js](https://codesandbox.io/s/recursing-ritchie-kbutq?file=/src/index.js)
- [Svelte](https://codesandbox.io/s/promistate-svelte-h86ll?file=/App.svelte)
- [Angular](https://codesandbox.io/s/angular-promistate-xf2j5?file=/src/app/app.component.html)
- [Vanilla JS](https://codesandbox.io/s/vanilla-promistate-vdyd3?file=/src/index.js)

## Comparison (example with Vue.js)

Expand Down Expand Up @@ -62,9 +63,6 @@ export default {

All under one variable 👍.

<details>
<summary>Click to toggle</summary>

```vue
<template>
<div v-if="userPromise.error">Whoops!</div>
Expand All @@ -89,10 +87,11 @@ export default {
}
</script>
```
</details>

## API

(See below for react hook example)

```javascript
import promistate from 'promistate'

Expand All @@ -101,6 +100,7 @@ const userPromise = promistate(async function callback(id) {
})

// later...
console.log(userPromise.value) // null
await userPromise.load(1)
console.log(userPromise.value) // { id: 1, name: '...' }
```
Expand Down Expand Up @@ -241,6 +241,16 @@ promise.value = 2
promise.isEmpty // false
```

If you use the react hook, do it like this instead:

```javascript
import { usePromistate } from 'promistate/lib/react'

const [promise, actions] = usePromistate(() => fetch('...'))

actions.setValue(2)
```

## Meta

### Compile project
Expand Down

0 comments on commit eb998b3

Please sign in to comment.