function useEffectOnece(effect) {
useEffect(effect, [])
}
function useMount(fn) {
useEffectOnce(() => {
fn()
})
}
function useUnmount(fn) {
const fnRef = useRef(fn)
fnRef.current = fn
useEffectOnce(() => () => fnRef.current())
};
function useAsyncEffect(effect, deps) {
useEffect(() => {
const e = effect()
if (!!e) {
if (typeof e.then === 'function') {
Promise.resolve(e)
} else {
return e
}
}
}, deps)
}
function useFirstMountState() {
const isFirst = useRef(true)
if (isFirst.current) {
isFirst.current = false
return true
}
return isFirst.current
}
function useUpdateEffect(effect, deps) {
const isFirstMount = useFirstMountState();
useEffect(() => {
if (!isFirstMount) {
return effect()
}
}, deps)
}
function useCustomCompareEffect(effect, deps, depsEqual) {
const ref = useRef(undefined)
if (!ref.current || !depsEqual(deps, ref.current)) {
ref.current = deps
}
useEffect(effect, ref.current)
}