use-last-callback
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

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>
  )
}

Package Sidebar

Install

npm i use-last-callback

Weekly Downloads

0

Version

0.0.1

License

ISC

Unpacked Size

4.05 kB

Total Files

6

Last publish

Collaborators

  • xuerzong