Skip to content

VimLeSai/useStateCallback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useStateCallback

It is a simple custom hook on top of useState to provide a callback after the state is updated, just like in Class Component.

You can pass the function in the second parameter of the set state, in that you will get an updated data as an argument.

for example,

import React, {  useEffect } 'react';
import useStateCallback from 'use-state-callback';

function App() {
    const [count, setCount] = useStateCallback(0)

    useEffect(() => {
        setCount(1, state => console.log('updated value', state)) // will show log with value 1
    }, [])

    return <div>
        count : {count}
    </div>
}

Important Note !

  • it requires at least 16.8 or higher version of react

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published