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

1.1.1 • Public • Published


react-use-that

<br />
react-use-that
npm package travis master

Basic and powful react hooks

Install

npm i react-use-that

Usages

useCallback

"useCallback Hooks" same as react/useCallback, more powerful than react/usecallback, the reference of useCallback's return value is unchanged.

import { useCallback } from 'react-use-that'
export default ({ p }) => {
    const cb = useCallback(() => {
        // ...
    }, [p])
    // do something with cb
}

useCurrent

"useCurrent Hooks" can get the value of the latest render function execution context.

import { useCurrent } from 'react-use-that'
export default ({ count }) => {
    const getCount = useCurrent(count)
    
    ...
    // can use getCount in other callback
    getCount() 
}

useState

"useState Hooks" can perform the callback in didUpdate caused by the corresponding setState.

import { useState } from 'react-use-that'
export default () => {
    const [count, setCount] = useState(0)
    
    ...
    // place setCount in other callback
    setCount(1, () => {
        // didUpdate
        ...
    }) 
}

useMount

"useMount Hooks" can perform the callback defined by the latest render function context before didMount or willUnmount. The parameter callback is only executed once in didMount, you don't need to care about redundant execution due to dependency changes.

import { useMount } from 'react-use-that'
export default () => {
    useMount(() => {
        // didMount
        
        return () => {
            // the return function is opt
            // willUnmount
        }
    })
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-use-that

Weekly Downloads

7

Version

1.1.1

License

Unlicense

Unpacked Size

17 kB

Total Files

35

Last publish

Collaborators

  • keshidong.dev