Reputation: 11
const [items, setItems] = useState([]);
useEffect(() => {
axios
.get(
`https://intense-wave-00513.herokuapp.com/addedProducts/${user.displayName}`
)
.then((data) => {
setItems(data.data);
});
}, [user.displayName]);
return(
<div>
{
items?.length?<p>somthing</p>:<Spinner/>
}
</div>
)
But when the api return empty data how to show 'no data found' In my case spinner is running all the time when no data found
Upvotes: 1
Views: 510
Reputation: 748
const [items, setItems] = useState([]);
const [isLoading, setLoading] = useState(false);
useEffect(() => {
setLoading(true);
axios
.get(
`https://intense-wave-00513.herokuapp.com/addedProducts/${user.displayName}`
)
.then((data) => {
setItems(data.data);
setLoading(false);
});
}, [user.displayName]);
return(
<div>
{
!isLoading? <> {items.length ? <p>somthing</p> : <p>data not found</p>} </> : <Spinner/>
}
</div>
)
Upvotes: 1