@td-design/rn-hooks
Version:
从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率
21 lines (18 loc) • 554 B
JavaScript
import { useEffect } from 'react';
import { isFunction } from '../utils/index.js';
/**
* 只在组件 mount 时执行的 Hook。也就是说 fn 函数只会执行一次
* @param fn mount 时执行的函数
*/
function useMount(fn) {
if (__DEV__) {
if (!isFunction(fn)) {
throw new Error("useMount expected parameter is a function, got ".concat(typeof fn));
}
}
useEffect(function () {
fn();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}
export { useMount as default };