@td-design/rn-hooks
Version:
从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率
23 lines (19 loc) • 629 B
JavaScript
;
var react = require('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 = react.useRef();
var currentRef = react.useRef();
if (shouldUpdate(currentRef.current, state)) {
prevRef.current = currentRef.current;
currentRef.current = state;
}
return prevRef.current;
}
module.exports = usePrevious;