@kingerez/usestatewithcallback
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

useStateWithCallback

I created this package to enable developers to use a functionality similar to what we used to have with the setState method.

Important caviat

Because of the way React works, the callback being called exists on the previous instantiation of the component. So I've updated the callback function to also pass the updated state.

Installation

npm i @kingerez/usestatewithcallback

-or-

yarn add @kingerez/usestatewithcallback

Import

import { useStateWithCallback } from '@kingerez/usestatewithcallback';

Usage

const [counter, setCounter] = useStateWithCallback(0);
setCounter(5, (newValue) => {
    console.log('Counter state updated. Current value:', newValue);
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i @kingerez/usestatewithcallback

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

13.8 kB

Total Files

5

Last publish

Collaborators

  • kingerez