UNPKG

@livelybone/use-force-update

Version:
28 lines (23 loc) 673 B
/** * Bundle of @livelybone/use-force-update * Generated: 2019-10-11 * Version: 1.0.1 * License: MIT * Author: 2631541504@qq.com */ import { useReducer } from 'react'; /** * @desc 通过 useReducer 实现,返回一个元组,第一个元素表示强制更新的次数 forceUpdateCount,第二个元素是 forceUpdate 函数 * * @desc Realized by useReducer * * @return [number, () => void] * The first element represents the count number of forced updates * The second element is the forceUpdate method * */ function useForceUpdate() { return useReducer(function (pre) { return pre + 1; }, 0); } export default useForceUpdate;