Skip to content

Commit

Permalink
readme updates addressing react injection
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Sep 12, 2019
1 parent d0e6a37 commit 67974ea
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Easy state management for react using hooks in less than 1kb.

---

Minimal example:
## Minimal example:

```javascript
import React from 'react';
Expand Down Expand Up @@ -43,23 +43,23 @@ export default App;

---

### Complete examples:
## Complete examples:

#### [Several counters, one value](https://codesandbox.io/s/v6zz2nwow5 'CodeSandBox')
### [Several counters, one value](https://codesandbox.io/s/v6zz2nwow5 'CodeSandBox')

Add as many counters as you want, it will all share the same global value.
Every time one counter add 1 to the global value, all counters will render.
The parent component won't render again.

---

#### [Asynchronous ajax requests](https://codesandbox.io/s/wqvykj5497 'CodeSandBox')
### [Asynchronous ajax requests](https://codesandbox.io/s/wqvykj5497 'CodeSandBox')

Search GitHub repos by username.
Handle the ajax request asynchronously with async/await.
Update the requests counter on every search.

### [ setRef vs setState ](https://codepen.io/nmccready/pen/vYBgrGR)
## [ setRef vs setState ](https://codepen.io/nmccready/pen/vYBgrGR)

Sometimes you just need to set a reference and wipe the state clean.

Expand All @@ -68,6 +68,12 @@ There are many use cases:
- reset / wipe
- tracking dom elements `ref={setRef}`

## Why do we allow React Injection?

- to support different React implementation
- to allow different versions of useEffect, useState or other hooks
- say to allow inspection for redux-devtools see [reinspect](https://github.com/troch/reinspect) to debug your global hooks

[npm-image]: https://img.shields.io/npm/v/@znemz/use-global-hook.svg
[npm-url]: https://www.npmjs.com/package/@znemz/use-global-hook
[travis-image]: https://img.shields.io/travis/nmccready/use-global-hook.svg
Expand Down

0 comments on commit 67974ea

Please sign in to comment.