SG
Size: a a a
SG
UU
SG
SG
AR
SG
SG
SG
setState({ isLoading: true })
SG
TS
setState({ isLoading: true })
function fetchData(fetcher) {
const promise = useRef(null);
const data = useRef(null);
const [forceUpdateDep, forceUpdate] = useState(0);
const [state, setState] = useState({
isLoading: false,
isError: false,
error: null,
});
useEffect(() => {
data.current = null;
setState({
isLoading: true,
isError: false,
error: null,
});
promise.current = fetcher()
.then((res) => {
data.current = res;
setState({
isLoading: false,
});
promise.current = null;
})
.catch((err) => {
setState({
isLoading: false,
isError: true,
error: err,
});
});
}, [fetcher, forceUpdateDep]);
const retry = useCallback(() => {
forceUpdate((val) => val + 1);
}, []);
return {
isLoading: state.isLoading,
isError: state.isError,
retry,
data: data.current,
};
}
TS
D
() => {
const div = useRef()
useEffect(() => {
if (dov.current && !captcha.alreadyRendered)
recaptcha.render('captcha-div')
}
return (
<>
...
<div id='captcha-id' ref={div} />
</>
)
}
dov.current && ...
. опечатка просто?SG
G
dov.current && ...
. опечатка просто?SG
YO
SS
YO
SS
YO