Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/YannickFricke/react-resettable-state
A custom hook for a resettable state
https://github.com/YannickFricke/react-resettable-state
Last synced: 4 days ago
JSON representation
A custom hook for a resettable state
- Host: GitHub
- URL: https://github.com/YannickFricke/react-resettable-state
- Owner: YannickFricke
- Created: 2020-04-22T09:12:32.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2024-05-13T02:55:44.000Z (6 months ago)
- Last Synced: 2024-08-01T19:53:31.732Z (3 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/react-resettable-state
- Size: 869 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# React resettable state
## About the project
Do you ever was in the situation where you want to reset your React.js state?
This project got you covered!
## How to use?
Now you want to see this small package in action? No problem!
1. Install the package:
- npm: `npm i react-resettable-state`
- yarn: `yarn add react-resettable-state`2. Import the package
```js
// JavaScript
const { useResettableState } = require('react-resettable-state');// TypeScript
import { useResettableState } from 'react-resettable-state';
```3. Use the package
```jsx
const App = () => {
const [counter, resetCounter, setCounter] = useResettableState(0);return (
Counter: {counter}
setCounter((currentCount) => currentCount + 1)}
>
Increment
Reset
);
};
```## Examples
Here are some examples which are written in TypeScript.
If you want to use JavaScript instead, look in the section above.- [Counter](https://codesandbox.io/s/react-resettable-state-counter-example-knun5)
- [Form data](https://codesandbox.io/s/react-resettable-state-form-example-sk1dw)## Typings?
Since this package is written in TypeScript it also ships with type definitions!
It doesn't matter if you are using JavaScript or TypeScript directly, any good IDE will show the type hints for this custom hook.