https://github.com/majidux/usestates
A custom hook for having multiple states. This package can only use in Reactjs.
https://github.com/majidux/usestates
hooks react react-hooks react-native reactjs strategy-design-pattern
Last synced: 9 months ago
JSON representation
A custom hook for having multiple states. This package can only use in Reactjs.
- Host: GitHub
- URL: https://github.com/majidux/usestates
- Owner: majidux
- Created: 2020-07-10T08:34:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-29T09:39:05.000Z (over 4 years ago)
- Last Synced: 2025-04-20T17:48:15.520Z (9 months ago)
- Topics: hooks, react, react-hooks, react-native, reactjs, strategy-design-pattern
- Language: TypeScript
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# useStates
A custom hook based on useReducer and inspired by strategy design pattern for having multiple states
###### With npm:
```javascript
npm install --save use-states-react
```
###### With yarn:
```javascript
yarn add use-states-react
```
This is how you are going to use it : =>
```javascript
import { useStates } from "use-states-react";
const initialState = {
name: "",
};
const Example = () => {
const [state, setState] = useStates(initialState);
const { name } = state;
const onChange = ({ target: { name, value } }) => {
setState(
{
[name]: value,
},
() => console.log("Callback function")
);
};
return (
<>
>
);
};
```