use-last-callback
v0.0.1
Published
A react hooks called 'use-last-callback'
Downloads
1
Maintainers
Readme
use-last-callback
React hooks for last callback
Install
yarn add use-last-callback
Usage
import { useState } from 'react'
import { useLastCallback } from 'use-last-callback'
const mockPromise = (content: string) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(content)
resolve(content)
})
})
}
const Page = () => {
const [c, setC] = useState(0)
const lastClickCallback = useLastCallback(mockPromise)
return (
<div>
<button onClick={() => {
lastCallback(c.toString())
setC(v => v + 1)
}}>
Button
</button>
</div>
)
}