Mutable State
Update reactjs state just like you update a literal object.. literally mutable-state
Requirements
You need react hooks to use this library which is not available in the current stable build 16.7.0. You may need to install the alpha version of reactjs and reactDOM
Installation
$ npm install mutable-state
OR Yarn
$ yarn add mutable-state
Usage
import React from "react";import useMutableState from "mutable-state"; { // just pass in the state let state = ; // WAYS TO UPDATE THE STATE const way1 = stateshoecount += 1; const way2 = state = shoe: count: stateshoecount - 1 ; // it's cool right? (: const way3 = statepenCount += 1; return <div> <h1>shoe size: stateshoecount</h1> <button =>Increment</button> </div> ;}
get
the value, you can't set
it, as this is the standard behaviour.
NOTCE : Using ES6+ destructuring you can only const size = ;// YOU CAN DO THISsize; //=> 0 // BUT NOT THIS ->size = 2; // NOPE .... THE STATE ISN'T UPDATED BCZ DESTRUCTURING ONLY COPIES THE `VALUE` NOT THE `SETTER` // BUT YOU CAN DO THISconst shoe = ; shoesize = 12; // YUP // SAD BUT THAT'S HOW IT'S IMPLEMENTED IN ALL THE BROWSERS