📌  相关文章
📜  在第一次渲染时不反应使用效果 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:48.039000             🧑  作者: Mango

代码示例1
//This is a way to build this effect as a custom hook
import React, { useEffect, useRef } from 'react';

const useDidMountEffect = (func, deps) => {
    const didMount = useRef(false);

    useEffect(() => {
        if (didMount.current) func();
        else didMount.current = true;
    }, deps);
}

export default useDidMountEffect;