Static version of the useState()
hook.
Component is not re-rendered when state gets changed till force update function is called.
const [getValue, setValue, forceUpdate] = useStaticState(0);
npm i -P use-static-state
import React from 'react';
import useStaticState from 'use-static-state';
function Counter() {
const [getCounter, setCounter, refreshCounter] = useStaticState(0);
function increase() {
setCounter(getCounter() + 1);
// or:
setCounter(counter => counter + 1);
}
function refresh() {
refreshCounter();
}
return <div>
{ getCounter() }
<button onClick={increase}>+</button>
<button onClick={refresh}>REFRESH</button>
</div>;
}