react hooks useEffect() cleanup for only componentWillUnmount?

前端 未结 5 1392
南笙
南笙 2020-12-12 12:32

Let me explain the result of this code for asking my issue easily.

const ForExample = () => {
    const [name, setName] = useState(\'\');
    const [usern         


        
5条回答
  •  一整个雨季
    2020-12-12 13:13

    you can use more than one useEffect

    for example if my variable is data1 i can use all of this in my component

    useEffect( () => console.log("mount"), [] );
    useEffect( () => console.log("will update data1"), [ data1 ] );
    useEffect( () => console.log("will update any") );
    useEffect( () => () => console.log("will update data1 or unmount"), [ data1 ] );
    useEffect( () => () => console.log("unmount"), [] );
    

提交回复
热议问题