Skip to content

Commit aad5457

Browse files
doctypercwelch5
authored andcommitted
fix: Add support for renderable Arrays of strings (#275)
* fix: Add support for anything renderable as children rather than just strings. Fixes #272
1 parent e23f4fb commit aad5457

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Helmet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ const Helmet = (Component) => class HelmetWrapper extends React.Component {
187187
return warn(`Only elements types ${VALID_TAG_NAMES.join(", ")} are allowed. Helmet does not support rendering <${child.type}> elements. Refer to our API for more information.`);
188188
}
189189

190-
if (nestedChildren && typeof nestedChildren !== "string") {
190+
if (
191+
nestedChildren &&
192+
typeof nestedChildren !== "string" &&
193+
(
194+
!Array.isArray(nestedChildren) || nestedChildren.some(nestedChild => typeof nestedChild !== "string")
195+
)
196+
) {
191197
throw new Error(`Helmet expects a string as a child of <${child.type}>. Did you forget to wrap your children in braces? ( <${child.type}>{\`\`}</${child.type}> ) Refer to our API for more information.`);
192198
}
193199
}

src/HelmetUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ const handleClientStateChange = (newState) => {
301301
};
302302

303303
const updateTitle = (title, attributes) => {
304-
if (typeof title === "string" && document.title !== title) {
305-
document.title = title;
304+
if (typeof title !== "undefined" && document.title !== title) {
305+
document.title = Array.isArray(title) ? title.join("") : title;
306306
}
307307

308308
updateAttributes(TAG_NAMES.TITLE, attributes);

0 commit comments

Comments
 (0)