Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/damianc/use-static-state
- Owner: damianc
- Created: 2021-08-13T16:07:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-13T16:38:19.000Z (over 3 years ago)
- Last Synced: 2024-04-27T01:21:36.878Z (8 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
}
```