forked from use-global-hook/use-global-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix website build process for typedoc not allowing overwrite of docs dir
- Loading branch information
Showing
27 changed files
with
6,232 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
**[@znemz/use-global-hook](README.md)** | ||
|
||
[Globals](globals.md) | ||
|
||
# @znemz/use-global-hook [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] | ||
|
||
Easy state management for react using hooks in less than 1kb. | ||
|
||
--- | ||
|
||
Minimal example: | ||
|
||
```javascript | ||
import React from 'react'; | ||
import useGlobalHook from '@znemz/use-global-hook'; | ||
|
||
const initialState = { | ||
counter: 0, | ||
}; | ||
|
||
const actions = { | ||
addToCounter: (store, amount) => { | ||
const newCounterValue = store.state.counter + amount; | ||
store.setState({ counter: newCounterValue }); | ||
}, | ||
}; | ||
|
||
const useGlobal = useGlobalHook({ React, initialState, actions }); | ||
|
||
const App = () => { | ||
const [globalState, globalActions] = useGlobal(); | ||
return ( | ||
<div> | ||
<p> | ||
counter: | ||
{globalState.counter} | ||
</p> | ||
<button type="button" onClick={() => globalActions.addToCounter(1)}> | ||
+1 to global | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
``` | ||
|
||
--- | ||
|
||
### Complete examples: | ||
|
||
#### [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') | ||
|
||
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) | ||
|
||
Sometimes you just need to set a reference and wipe the state clean. | ||
|
||
There are many use cases: | ||
|
||
- reset / wipe | ||
- tracking dom elements `ref={setRef}` | ||
|
||
[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 | ||
[travis-url]: https://travis-ci.org/nmccready/use-global-hook | ||
[coveralls-image]: https://coveralls.io/repos/github/nmccready/use-global-hook/badge.svg | ||
[coveralls-url]: https://coveralls.io/github/nmccready/use-global-hook?branch=master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
**[@znemz/use-global-hook](README.md)** | ||
|
||
[Globals](globals.md) | ||
|
||
# @znemz/use-global-hook | ||
|
||
## Index | ||
|
||
### External modules | ||
|
||
* ["actions"](modules/_actions_.md) | ||
* ["index"](modules/_index_.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
**[@znemz/use-global-hook](../README.md)** | ||
|
||
[Globals](../globals.md) › ["actions"](../modules/_actions_.md) › [InnerBaseActions](_actions_.innerbaseactions.md) | ||
|
||
# Interface: InnerBaseActions <**T**> | ||
|
||
## Type parameters | ||
|
||
▪ **T** | ||
|
||
## Hierarchy | ||
|
||
* **InnerBaseActions** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [setRef](_actions_.innerbaseactions.md#setref) | ||
* [setState](_actions_.innerbaseactions.md#setstate) | ||
|
||
## Properties | ||
|
||
### setRef | ||
|
||
• **setRef**: *function* | ||
|
||
*Defined in [actions.ts:10](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/actions.ts#L10)* | ||
|
||
#### Type declaration: | ||
|
||
▸ (`store`: [Store](_index_.store.md)‹T, [OuterBaseActions](_actions_.outerbaseactions.md)‹T››, `newState`: T, `doDigest?`: boolean): *void* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`store` | [Store](_index_.store.md)‹T, [OuterBaseActions](_actions_.outerbaseactions.md)‹T›› | | ||
`newState` | T | | ||
`doDigest?` | boolean | | ||
|
||
___ | ||
|
||
### setState | ||
|
||
• **setState**: *function* | ||
|
||
*Defined in [actions.ts:9](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/actions.ts#L9)* | ||
|
||
#### Type declaration: | ||
|
||
▸ (`store`: [Store](_index_.store.md)‹T, [OuterBaseActions](_actions_.outerbaseactions.md)‹T››, `newState`: T, `doDigest?`: boolean): *void* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`store` | [Store](_index_.store.md)‹T, [OuterBaseActions](_actions_.outerbaseactions.md)‹T›› | | ||
`newState` | T | | ||
`doDigest?` | boolean | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
**[@znemz/use-global-hook](../README.md)** | ||
|
||
[Globals](../globals.md) › ["actions"](../modules/_actions_.md) › [OuterBaseActions](_actions_.outerbaseactions.md) | ||
|
||
# Interface: OuterBaseActions <**T**> | ||
|
||
## Type parameters | ||
|
||
▪ **T** | ||
|
||
## Hierarchy | ||
|
||
* **OuterBaseActions** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [setRef](_actions_.outerbaseactions.md#setref) | ||
* [setState](_actions_.outerbaseactions.md#setstate) | ||
|
||
## Properties | ||
|
||
### setRef | ||
|
||
• **setRef**: *function* | ||
|
||
*Defined in [actions.ts:5](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/actions.ts#L5)* | ||
|
||
#### Type declaration: | ||
|
||
▸ (`newState`: T, `doDigest?`: boolean): *void* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`newState` | T | | ||
`doDigest?` | boolean | | ||
|
||
___ | ||
|
||
### setState | ||
|
||
• **setState**: *function* | ||
|
||
*Defined in [actions.ts:4](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/actions.ts#L4)* | ||
|
||
#### Type declaration: | ||
|
||
▸ (`newState`: T, `doDigest?`: boolean): *void* | ||
|
||
**Parameters:** | ||
|
||
Name | Type | | ||
------ | ------ | | ||
`newState` | T | | ||
`doDigest?` | boolean | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
**[@znemz/use-global-hook](../README.md)** | ||
|
||
[Globals](../globals.md) › ["index"](../modules/_index_.md) › [ReactLib](_index_.reactlib.md) | ||
|
||
# Interface: ReactLib | ||
|
||
## Hierarchy | ||
|
||
* **ReactLib** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [useEffect](_index_.reactlib.md#useeffect) | ||
* [useState](_index_.reactlib.md#usestate) | ||
|
||
## Properties | ||
|
||
### useEffect | ||
|
||
• **useEffect**: *[UseEffect](../modules/_index_.md#useeffect)* | ||
|
||
*Defined in [index.ts:7](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L7)* | ||
|
||
___ | ||
|
||
### useState | ||
|
||
• **useState**: *[UseState](../modules/_index_.md#usestate)* | ||
|
||
*Defined in [index.ts:8](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L8)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
**[@znemz/use-global-hook](../README.md)** | ||
|
||
[Globals](../globals.md) › ["index"](../modules/_index_.md) › [Store](_index_.store.md) | ||
|
||
# Interface: Store <**T, OuterA**> | ||
|
||
## Type parameters | ||
|
||
▪ **T** | ||
|
||
▪ **OuterA** | ||
|
||
## Hierarchy | ||
|
||
* **Store** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [actions](_index_.store.md#actions) | ||
* [listeners](_index_.store.md#listeners) | ||
* [setRef](_index_.store.md#setref) | ||
* [setState](_index_.store.md#setstate) | ||
* [state](_index_.store.md#state) | ||
|
||
## Properties | ||
|
||
### actions | ||
|
||
• **actions**: *OuterA* | ||
|
||
*Defined in [index.ts:47](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L47)* | ||
|
||
___ | ||
|
||
### listeners | ||
|
||
• **listeners**: *Dispatch‹unknown›[]* | ||
|
||
*Defined in [index.ts:49](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L49)* | ||
|
||
___ | ||
|
||
### setRef | ||
|
||
• **setRef**: *[SetRefFn](../modules/_index_.md#setreffn)‹T›* | ||
|
||
*Defined in [index.ts:46](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L46)* | ||
|
||
___ | ||
|
||
### setState | ||
|
||
• **setState**: *[SetStateFn](../modules/_index_.md#setstatefn)‹T›* | ||
|
||
*Defined in [index.ts:45](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L45)* | ||
|
||
___ | ||
|
||
### state | ||
|
||
• **state**: *T* | ||
|
||
*Defined in [index.ts:48](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L48)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
**[@znemz/use-global-hook](../README.md)** | ||
|
||
[Globals](../globals.md) › ["index"](../modules/_index_.md) › [UseStoreProps](_index_.usestoreprops.md) | ||
|
||
# Interface: UseStoreProps <**T, InnerA, OuterA, WorkR**> | ||
|
||
## Type parameters | ||
|
||
▪ **T** | ||
|
||
▪ **InnerA** | ||
|
||
▪ **OuterA** | ||
|
||
▪ **WorkR** | ||
|
||
## Hierarchy | ||
|
||
* **UseStoreProps** | ||
|
||
## Index | ||
|
||
### Properties | ||
|
||
* [React](_index_.usestoreprops.md#react) | ||
* [actions](_index_.usestoreprops.md#optional-actions) | ||
* [hookWork](_index_.usestoreprops.md#optional-hookwork) | ||
* [initialState](_index_.usestoreprops.md#optional-initialstate) | ||
* [initializer](_index_.usestoreprops.md#optional-initializer) | ||
|
||
## Properties | ||
|
||
### React | ||
|
||
• **React**: *[ReactLib](_index_.reactlib.md)* | ||
|
||
*Defined in [index.ts:28](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L28)* | ||
|
||
___ | ||
|
||
### `Optional` actions | ||
|
||
• **actions**? : *InnerA | [InnerBaseActions](_actions_.innerbaseactions.md)‹T›* | ||
|
||
*Defined in [index.ts:30](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L30)* | ||
|
||
___ | ||
|
||
### `Optional` hookWork | ||
|
||
• **hookWork**? : *function* | ||
|
||
*Defined in [index.ts:32](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L32)* | ||
|
||
#### Type declaration: | ||
|
||
▸ (): *WorkR* | ||
|
||
___ | ||
|
||
### `Optional` initialState | ||
|
||
• **initialState**? : *T* | ||
|
||
*Defined in [index.ts:29](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L29)* | ||
|
||
___ | ||
|
||
### `Optional` initializer | ||
|
||
• **initializer**? : *[Initializer](../modules/_index_.md#initializer)‹T, OuterA›* | ||
|
||
*Defined in [index.ts:31](https://github.com/nmccready/use-global-hook/blob/43f09fb/src/index.ts#L31)* |
Oops, something went wrong.