Fix exception thrown with zero links. Closes #2833

This commit is contained in:
Gabe Kangas 2023-03-18 11:49:20 -07:00
parent a2af4f5729
commit 7e4d147940
No known key found for this signature in database
GPG Key ID: 4345B2060657F330

View File

@ -1,15 +1,32 @@
import Image from 'next/image'; import Image from 'next/image';
import { FC } from 'react'; import { FC } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { SocialLink } from '../../../interfaces/social-link.model'; import { SocialLink } from '../../../interfaces/social-link.model';
import { ComponentError } from '../ComponentError/ComponentError';
import styles from './SocialLinks.module.scss'; import styles from './SocialLinks.module.scss';
export type SocialLinksProps = { export type SocialLinksProps = {
links: SocialLink[]; links: SocialLink[];
}; };
export const SocialLinks: FC<SocialLinksProps> = ({ links }) => ( export const SocialLinks: FC<SocialLinksProps> = ({ links }) => {
if (!links?.length) {
return null;
}
return (
<ErrorBoundary
// eslint-disable-next-line react/no-unstable-nested-components
fallbackRender={({ error, resetErrorBoundary }) => (
<ComponentError
componentName="SocialLinks"
message={error.message}
retryFunction={resetErrorBoundary}
/>
)}
>
<div className={styles.links}> <div className={styles.links}>
{links.map(link => ( {links?.map(link => (
<a <a
key={link.platform} key={link.platform}
href={link.url} href={link.url}
@ -28,4 +45,6 @@ export const SocialLinks: FC<SocialLinksProps> = ({ links }) => (
</a> </a>
))} ))}
</div> </div>
); </ErrorBoundary>
);
};