UNPKG

@amsterdam/design-system-react

Version:

All React components from the Amsterdam Design System. Use it to compose pages in your website or application.

31 lines (30 loc) 846 B
/** * @license EUPL-1.2+ * Copyright Gemeente Amsterdam */ import { useEffect, useState } from 'react'; export const useAddErrorCountToDocumentTitle = ( /** The list of error messages used to calculate the error count. */ errors, /** The text following the error count. */ label = { plural: 'invoerfouten', singular: 'invoerfout', }) => { const [documentTitle, setDocumentTitle] = useState(); useEffect(() => { setDocumentTitle(document.title); }, []); if (!documentTitle) return null; if (errors.length === 1) { document.title = `(${errors.length} ${label.singular}) ${documentTitle}`; } else if (errors.length > 1) { document.title = `(${errors.length} ${label.plural}) ${documentTitle}`; } else { document.title = documentTitle; } return null; };