my React notes

Hooks

useEffect

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("data1 update"), [ data1 ] );
useEffect( () => console.log("any update") );
useEffect( () => () => console.log("data1 update or unmount"), [ data1 ] );
useEffect( () => () => console.log("unmount"), [] );

How to query data using hooks?

useEffect(()  => {
        const fetchData = async () => {
            const result =  await axios('url');
            setData(result.data);
        };
        fetchData();
    }, []);

Вам также может понравиться

About the Author: Vladimir Kusakin

Hi. I am web developer. For the past 9 years, I've been developing applications for the web using mostly PHP and Python. About me

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *