use-static-state

1.1.1 • Public • Published

use-static-state

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

Install

npm i -P use-static-state

Counter Example

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i use-static-state

      Weekly Downloads

      0

      Version

      1.1.1

      License

      ISC

      Unpacked Size

      1.75 kB

      Total Files

      3

      Last publish

      Collaborators

      • damianc