reakcja komponent aktualizacji po wywołaniu interfejsu API
const Settings = () => {
const [state, setState] = useState({});
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
const getAllInformation = async () => {
// start loading
setIsLoading(true);
// make the request here
const data = await fetch();
setState({ ...data });
// already finished here
setIsLoading(false);
};
getAllInformation()
}, []);
return (
<div>
{isLoading ? (
<Loading />
) : (
{
/* MORE CODE */
}
)}
</div>
);
};
miletoo