1.0.3 • Published 3 years ago

use-states-react v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

useStates

A custom hook based on useReducer and inspired by strategy design pattern for having multiple states

With npm:
npm install --save use-states-react
With yarn:
yarn add use-states-react

This is how you are going to use it : =>

import { useStates } from "use-states-react";

const initialState = {
  name: "",
};

const Example = () => {
  const [state, setState] = useStates<any>(initialState);
  const { name } = state;
  const onChange = ({ target: { name, value } }) => {
    setState(
      {
        [name]: value,
      },
      () => console.log("Callback function")
    );
  };
  return (
    <>
      <input name="name" type="text" value={name} onChange={onChange} />
    </>
  );
};
1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago