Skip to content

Commit

Permalink
feat: add useWait hook
Browse files Browse the repository at this point in the history
  • Loading branch information
f authored and streamich committed Nov 6, 2018
1 parent eca432a commit 61c6058
Show file tree
Hide file tree
Showing 7 changed files with 16,536 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- [`useOutsideClick`](./docs/useOutsideClick.md) — triggers callback when user clicks outside target area.
- [`useSpeech`](./docs/useSpeech.md) — synthesizes speech from a text string. [![][img-demo]](https://codesandbox.io/s/n090mqz69m)
- [`useVideo`](./docs/useVideo.md) — plays video, tracks its state, and exposes playback controls.
- [`useWait`](./docs/useWait.md) — complex waiting management for UIs.
<br/>
<br/>
- [**Animations**](./docs/Animations.md)
Expand Down
36 changes: 36 additions & 0 deletions docs/useWait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# `useWait`

React waiting management hook.

## Usage

```jsx
import { useWait } from 'react-use'

function UserCreateButton() {
const { startWaiting, endWaiting, isWaiting, Wait } = useWait();

return (
<button
onClick={() => startWaiting("creating user")}
disabled={isWaiting("creating user")}
>
<Wait message="creating user" waiting={<div>Creating user!</div>}>
Create User
</Wait>
</button>
);
}
```

And you should wrap your `App` with `Waiter` component. It's actually a `Context.Provider` that provides a loading context to the component tree.

```jsx
const rootElement = document.getElementById("root");
ReactDOM.render(
<useWait.Waiter>
<App />
</useWait.Waiter>,
rootElement
);
```
Loading

0 comments on commit 61c6058

Please sign in to comment.