Skip to content

Commit

Permalink
fix readme improve index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
HollyPony committed Apr 11, 2020
1 parent 07ef6fe commit 3170840
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# React-Use-State-Context
# React-Use-State-Reducer

A hook to avoid multiple declaration of `const [xLoading, setXLoading] = useState(false)`

## Sample

`npm i react-use-state-context`
`npm i react-use-state-reducer`

```js
import React from "react";
Expand Down Expand Up @@ -38,7 +38,3 @@ export default function App() {

ReactDOM.render(<App />, document.getElementById("root"));
```

## Install

- `npm i react-rest-state-context`
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'

const reducer = (state, action) =>
Object.assign({}, state, { [action.type]: action.data })
const reducer = (state, action) => Object.assign({}, state, action)

export const useStateReducer = (initialState = {}) => {
const [state, dispatch] = React.useReducer(reducer, initialState)

const setState = React.useCallback((data, type) => dispatch({ type, data }), [
dispatch
])
const setState = React.useCallback(
(data, ctx) => dispatch({ [ctx]: data }),
[dispatch]
)

return [state, setState]
}
Expand Down

0 comments on commit 3170840

Please sign in to comment.