1.1.1 • Published 4 years ago

react-use-that v1.1.1

Weekly downloads
9
License
Unlicense
Repository
github
Last release
4 years ago

Install

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

4 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago