useforcestate

React State Manager.

Usage no npm install needed!

<script type="module">
  import useforcestate from 'https://cdn.skypack.dev/useforcestate';
</script>

README

Use Force State

Mutable React State

import {useForce} from "useforcestate"

function App() {
    const [state,force,sub,set] = useForce({count:0,
    people:[{name:"Lorem", age:21}]});

    sub((prev,current) => {
        console.log(`The state was ${prev}, now it is ${current}`);
    })

    return(
        <div>
            <h1> {state.count} <h1>
            <button onClick={() => force(() => state.count++)}> Increment</button>

            {state.people.map((person,index) => <p key={index}>{person.name}</p>)}
            <button onClick={() => force(() => state.people[0].age++)}>Increase Age</button>
            button onClick={() => force(() => state.people[0].name="Ipsum")}>Update Name</button>
            <button onClick={() => set({...state,count:25})}> Set State </button>
        </div>
    )
}