Add the dependency:
npm i @freakycoder/react-use-state-with-callback
Zero Dependency
import useStateWithCallback from "@freakycoder/react-use-state-with-callback";
const [isSelected, setIsSelected] = useStateWithCallback<boolean>(false);
// USAGE
setIsSelected(true, (newValue: boolean) => console.log(newValue)); // true
Big thanks to MJ Studio
from StackoverFlow. I just converted his awesome wrapper solution to a library.
FreakyCoder, kurayogun@gmail.com
React Use State with Callback is available under the MIT license. See the LICENSE file for more info.