react-hookstore
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "react-hookstore", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A state management library for react using the bleeding edge hooks feature", | ||
@@ -5,0 +5,0 @@ "main": "dist/react-hookstore.js", |
@@ -13,4 +13,4 @@ # React Hook Store | ||
This is the most basic implementation of the library. create a store with its initial state. | ||
Later, call useStore inside components to retrive its state and setState method. | ||
The value passed as the first argument to the setState method will be the new state. no reducer required (but you can use it, see the advanced example down below). | ||
Later, call `useStore` inside components to retrive its state and setState method. | ||
The value passed as the first argument to the setState method will be the new state. no reducer required (but you can use a reducer, see the advanced example down below). | ||
@@ -63,3 +63,3 @@ ```javascript | ||
// when a reducer is being used, you must return a new state object | ||
switch action.type: | ||
switch action.type { | ||
case 'add': | ||
@@ -81,2 +81,3 @@ const id = ++state.idCount; | ||
return todos; | ||
} | ||
} | ||
@@ -122,13 +123,13 @@ }); | ||
## API | ||
### `createStore({ state?={}, name?='store', reducer?=null })` | ||
### `createStore(config={ state, name, reducer })` | ||
Creates a store to be used across the entire application. | ||
### Arguments | ||
#### `state:* = {}` | ||
It can be of any data type. | ||
#### `name:String = 'store'` | ||
#### `config.state:* = {}` | ||
The store's initial state. it can be any data type. defaults to an empty object. Optional | ||
#### `config.name:String = 'store'` | ||
The namespace for your store, it can be used to better identify the store across the application. Optional | ||
#### `reducer:Function = null` | ||
You can specify a reducer function to take care of state changes. the reducer functions receives two arguments, the previous state and the payload that triggered the state update. the function must returns a new state, if not, the new state will be `null` | ||
#### `config.reducer:Function = null` | ||
You can specify a reducer function to take care of state changes. the reducer functions receives two arguments, the previous state and the action that triggered the state update. the function must return a new state, if not, the new state will be `null`. Optional | ||
### `useStore(storeName?='store')` | ||
A function that returns a pair with the current state and the handler method for the specified store. | ||
### `useStore(storeName='store')` | ||
A function that returns a pair with the current state and the handler method for the specified store. |
20672
132