Похожие чаты

Let url = 'https://google.com' useEffect(() => {

console.log(`fetching ${url}...`)
}, [url])

Is something like that ok?

6 ответов

14 просмотров

You do it like this: let url = 'https://google.com' useEffect(() => { console.log(`fetching ${url}...`) }, [])

the difference is, it re-renders every time the url changes but when given empty brackets, it only renders once before the components are loaded

You can also use the below model (though there are efficient & better ways using SWR, React Query, etc..) import { useEffect, useState } from "react"; import { getUserDetails } from "../api/services"; export default function useUser() { const [loading, setLoading] = useState<boolean>(true); const [user, setUser] = useState<any>({}); useEffect(() => { setLoading(true); getUserDetails().then(data => { setUser(data.data.data); setLoading(false); }).catch(error => { console.log(error) }); }, []); return { user, loading }; }

Void- Автор вопроса
Ali Souri
the difference is, it re-renders every time the ur...

yea and most of the time I don't need it to fech again every redner

Похожие вопросы

Обсуждают сегодня

Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
32
А чем вам питонисты не угодили?😂
.
79
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
Язык Си можно выучить за день? По книжке ANSI C на 230 страниц
Vincent Vegan
29
Привет, запускаю werf в dind в k8s, получаю ошибку на этапе build/beforeSetup: /.werf/stapel/embedded/bin/bash: /.werf/scripts/5898bdfe5214357d3706b879cc8d3d78460fb379607cbd...
florius0
7
Hello. Could you please help me with finding all coordinates within a radius using a spatial index, given that I have a table with coordinates? SET @lng = 37.57925; SET @lat ...
Rinchin G
4
Всех приветствую. Направьте меня в нужное русло. Постепенно переписываю проект с delphi на lazarus. Приложение - обычный windows/linux клиент для бд firebird. Тут все хорошо. ...
Mishutka
8
Привет всем, подскажите, есть сайт на ево 1.4, надо сделать его мультиязычным, структура документов одинаковой останется, чисто тексты разные, свои тв для каждого языка, поддо...
Oleg
7
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Why ftm dumping??
Sabah Shabu
8
Карта сайта