Skip to content

Commit

Permalink
added use-redux-state returns apis doc
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Feb 21, 2022
1 parent 7551692 commit 51216f2
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions website/docs/apis/hooks/use-redux-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ useReduxState(config?: {
### `returns{}`

- [selector](../selector.md)
- [setState](../set-state.md)
- [setState](./use-redux-state#setstate)
- [getState](./use-redux-state#getstate)
- [action](../action.md)
- [cleanup](../cleanup.md)
Expand Down Expand Up @@ -172,8 +172,9 @@ export default App
```

## Apis

### getState
function to get the state for a given state path.
function to get states for a given state path in the redux store.

## `Arguments`

Expand Down Expand Up @@ -217,3 +218,40 @@ const Component = () => {
}, [])
}
```

### setState

function to update states in the redux store.

## `Arguments`

### **payload**|**setter()?**

(*payload*) value to set in the state or (*setter*) function to determine how the state should be set.

```js
setState(payload: any | setter?: (state, payload) => newState)
```

## `Example`

```jsx
import { useReduxState } from 'use-redux-states'

const Component = () => {
const { setState } = useReduxState({
state: {
state1: []
},
path: 'todos.completed'
})

console.log(
setState((state) => {
state.state1.push(payload)
return state
})
)
// {state1: [1]}
}
```

0 comments on commit 51216f2

Please sign in to comment.