Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/damianc/use-static-state

Static version of the useState() hook.
https://github.com/damianc/use-static-state

Last synced: about 1 month ago
JSON representation

Static version of the useState() hook.

Awesome Lists containing this project

README

        

# 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


{ getCounter() }
+
REFRESH
;
}
```