LostHighway LostHighway 16.02.2021, 21:59:02 0 + #pytanie #programowanie #reactconst [url, setUrl] = React.useState(null) React.useEffect(() => { const interval = setInterval(() => { if (url !== document.URL) { console.log('in auth', url, document.URL) setUrl(document.URL) } }, 1000); return () => clearInterval(interval); }, []);dlaczego state się k---a nie zapisuje? Kod w providerze...
rEwx rEwx 16.02.2021, 22:03:29 via Wykop Mobilny (Android) 0 + @LostHighway: pewnie nie spełnia warunku?E: document.URL nie jest undefined?
LostHighway LostHighway 16.02.2021, 22:07:00 0 + @rEwx: Właśnie zawsze spełnia, state się nie aktualizuje... Już rzygam tym reduxem...in auth null http://localhost:8000/***/fcd32e41-c204-45dc-8f85-557e9c7148bd
rEwx rEwx 16.02.2021, 22:08:56 via Wykop Mobilny (Android) 0 + @LostHighway: ok czyli loguje Ci 'in auth' a state dalej null? Sprawdzasz to w toolsach?
LostHighway LostHighway 16.02.2021, 22:10:12 1 + O dziwo... let urlT = nullconst [url, setUrl] = React.useState(null) React.useEffect(() => { const interval = setInterval(() => {Pokaż całość
rEwx rEwx 16.02.2021, 22:12:33 via Wykop Mobilny (Android) 0 + @LostHighway: heh to ciekawe, bo tej pierwszej wersji też powinno hulać
LostHighway LostHighway 16.02.2021, 22:13:31 0 + Przepuszczenie przez tempową urlT już uaktualnia state... Dlatego tej k---y nienawidzę...
S.....8 konto usunięte 16.02.2021, 22:34:48 0 + @LostHighway: powstawiaj wszedzie debugger; to sie migiem dowiesz co jest nie tak
derecki derecki 17.02.2021, 01:00:53 1 + @LostHighway: z interwałami w useEffect zawsze są jakieś problemy, przeczytaj ten artykuł często korzystam z jego hookow które ma na githubie. https://overreacted.io/making-setinterval-declarative-with-react-hooks/
LostHighway LostHighway 17.02.2021, 08:41:55 0 + @derecki: O i to jest rozwiązanie, dziękuję bardzo :)
const [url, setUrl] = React.useState(null)
React.useEffect(() => {
const interval = setInterval(() => {
if (url !== document.URL) {
console.log('in auth', url, document.URL)
setUrl(document.URL)
}
}, 1000);
return () => clearInterval(interval);
}, []);
dlaczego state się k---a nie zapisuje? Kod w providerze...
E: document.URL nie jest undefined?
Już rzygam tym reduxem...
in auth null http://localhost:8000/***/fcd32e41-c204-45dc-8f85-557e9c7148bdlet urlT = null
const [url, setUrl] = React.useState(null)
React.useEffect(() => {
const interval = setInterval(() => {
Dlatego tej k---y nienawidzę...