react-resettable-state
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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
  1. Import the package
// JavaScript
const { useResettableState } = require('react-resettable-state');

// TypeScript
import { useResettableState } from 'react-resettable-state';
  1. Use the package
const App = () => {
    const [counter, resetCounter, setCounter] = useResettableState(0);

    return (
        <div>
            <div>Counter: {counter}</div>
            <button
                onClick={() => setCounter((currentCount) => currentCount + 1)}
            >
                Increment
            </button>
            <button onClick={resetCounter}>Reset</button>
        </div>
    );
};

Examples

Here are some examples which are written in TypeScript. If you want to use JavaScript instead, look in the section above.

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.

/react-resettable-state/

    Package Sidebar

    Install

    npm i react-resettable-state

    Weekly Downloads

    4

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    6.91 kB

    Total Files

    12

    Last publish

    Collaborators

    • yannickfricke