Addressing Helmet crash

This commit is contained in:
Jeff Avallone 2019-03-28 06:25:23 -04:00
parent 42b3d0a9d8
commit 8d78f41ed6
2 changed files with 29 additions and 22 deletions

View File

@ -5,13 +5,15 @@ exports[`Metadata rendering 1`] = `
<span <span
data-component="HelmetWrapper" data-component="HelmetWrapper"
data-props="{ data-props="{
\\"htmlAttributes\\": {} \\"title\\": \\"Regexper\\",
\\"htmlAttributes\\": {},
\\"meta\\": [
{
\\"name\\": \\"description\\"
}
]
}" }"
> />
<title>
Regexper
</title>
</span>
</DocumentFragment> </DocumentFragment>
`; `;
@ -20,16 +22,15 @@ exports[`Metadata rendering with a title and description 1`] = `
<span <span
data-component="HelmetWrapper" data-component="HelmetWrapper"
data-props="{ data-props="{
\\"htmlAttributes\\": {} \\"title\\": \\"Regexper - Testing\\",
\\"htmlAttributes\\": {},
\\"meta\\": [
{
\\"name\\": \\"description\\",
\\"content\\": \\"Test description\\"
}
]
}" }"
>
<title>
Regexper - Testing
</title>
<meta
content="Test description"
name="description"
/> />
</span>
</DocumentFragment> </DocumentFragment>
`; `;

View File

@ -5,14 +5,20 @@ import { Helmet } from 'react-helmet';
const Metadata = ({ title, description }) => { const Metadata = ({ title, description }) => {
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const htmlAttributes = { const helmetProps = {
title: title ? `Regexper - ${ title }` : 'Regexper',
htmlAttributes: {
lang: i18n.language lang: i18n.language
},
meta: [
{
name: 'description',
content: description
}
]
}; };
return <Helmet htmlAttributes={ htmlAttributes }> return <Helmet { ...helmetProps }></Helmet>;
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
{ description && <meta name="description" content={ description } /> }
</Helmet>;
}; };
Metadata.propTypes = { Metadata.propTypes = {