Skip to content

damianc/use-static-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Static version of the useState() hook.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published