https://github.com/vipulpathak113/set-state-callback
This is a npm package which will be used in getting set state callback in functional component using hooks
https://github.com/vipulpathak113/set-state-callback
hooks javascript react react-hooks
Last synced: about 2 months ago
JSON representation
This is a npm package which will be used in getting set state callback in functional component using hooks
- Host: GitHub
- URL: https://github.com/vipulpathak113/set-state-callback
- Owner: vipulpathak113
- Created: 2021-12-26T18:19:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-15T14:42:13.000Z (10 months ago)
- Last Synced: 2025-03-17T00:29:06.088Z (3 months ago)
- Topics: hooks, javascript, react, react-hooks
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/set-state-callback
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# set-state-callback
A React library used in getting callbacks for setstate for Hooks.
## It solves the problem in functional component using hooks
Currently we do not get any callback for setState in functional components like we used to get in class components which is sometimes creates problem as setstate is asynchronous and we need to use latest value just after setting the state. So it helps in addressing this problem.## Installation
npm:
```bash
npm install set-state-callback
```Yarn:
```bash
yarn add set-state-callback
```
## UsageImport the module:
```javascript
import useStateCallback from 'set-state-callback'
```## Example
```javascript
import useStateCallback from 'set-state-callback'// same sytax as the hooks
const [state,setState]= useStateCallback();const testFunc=()=>{
setState(newValueToSet,(newValue)=>{
console.log(newValue) // This will be the new value you just set in the state.
//Now you get the callback for setState where you can proceed using the latest value})
}```