Skip to content

Create a setState function, similar to this.setState to be used with React Hooks

Notifications You must be signed in to change notification settings

wviveiro/react-hook-setstate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-hook-setstate

Use setState function in react hooks as you would use in react classes.

Install

npm install -S react-hook-setstate

Usage

import createState from 'react-hook-setstate';

const MyComponent = () => {
  const [state, setState] = createState({counter1: 0, counter2: 0});
  
  return (
    <div>
        Counter 1: {state.counter1}<br />
        <button onClick={() => setState({counter1: state.counter1 + 1})}> 
            Add
        </button>
        <hr />
        Counter 2: {state.counter2}<br />
        <button onClick={() => setState({counter2: state.counter2 + 1})}> 
            Add
        </button>
    </div>
  );
}

About

Create a setState function, similar to this.setState to be used with React Hooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published