Skip to content

A custom hook for having multiple states. This package can only use in Reactjs.

Notifications You must be signed in to change notification settings

majidux/useStates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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} />
    </>
  );
};

About

A custom hook for having multiple states. This package can only use in Reactjs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published