Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

Reactjs How would I display a simple error if no data is fetched from api?

$
0
0

I'm struggling to find a way of adding an error message is filteredCountries from an api === 0. How would I best do this is a simple manner? Or is there a simple way to route to a 404 page?

I can think along the correct lines it's just not clicking!

const CountryList = ({ filteredCountries, isLoading }) => {
  return (
    <div className='card-list'>
      {isLoading ? (
        <Loader isLoading={isLoading} />
      ) : (
        filteredCountries.map((country) => (
          <>
            <Country
              key={country.name}
              id={country.alpha3Code}
              country={country}
            />
          </>
        ))
      )}
    </div>
  );
};
export default CountryList;

Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>