UNPKG

@td-design/rn-hooks

Version:

从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率

21 lines (18 loc) 609 B
import { useRef } from 'react'; var defaultShouldUpdate = function (a, b) { return !Object.is(a, b); }; /** * 保存上一次状态的 Hook。 * @param state 初始state * @param shouldUpdate 判断是否更新的函数 */ function usePrevious(state, shouldUpdate) { if (shouldUpdate === void 0) { shouldUpdate = defaultShouldUpdate; } var prevRef = useRef(); var currentRef = useRef(); if (shouldUpdate(currentRef.current, state)) { prevRef.current = currentRef.current; currentRef.current = state; } return prevRef.current; } export { usePrevious as default };