danalloway / react-country-flag

React component for emoji/svg country flags.
https://danalloway.github.io/react-country-flag/
MIT License
255 stars 43 forks source link

Handle a 404 error #59

Closed mccm2310 closed 1 year ago

mccm2310 commented 2 years ago

There is no way to handle a query error if the countryCode doesn't exist in cdnjs flags. For example, 'GZ' or 'AN'.

keytrap-x86 commented 1 year ago

Yes there is -> onError event.

<ReactCountryFlag
    className="h-4 w-4"
    countryCode={movie.lang.toLowerCase()}
    svg
    onError={() => console.log('error')} />
danalloway commented 1 year ago

@keytrap-x86 thank you for that example!

@mccm2310 this library is just a wrapper around an img tag for SVG flags, and a span tag for emoji's, all props pass through so the comment above is a perfect example of that