Skip to content

Commit

Permalink
fix: Add support for renderable Arrays of strings (#275)
Browse files Browse the repository at this point in the history
* fix: Add support for anything renderable as children rather than just strings.

Fixes #272
  • Loading branch information
doctyper authored and cwelch5 committed May 9, 2017
1 parent e23f4fb commit aad5457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Helmet.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ const Helmet = (Component) => class HelmetWrapper extends React.Component {
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.`);
}

if (nestedChildren && typeof nestedChildren !== "string") {
if (
nestedChildren &&
typeof nestedChildren !== "string" &&
(
!Array.isArray(nestedChildren) || nestedChildren.some(nestedChild => typeof nestedChild !== "string")
)
) {
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.`);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/HelmetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ const handleClientStateChange = (newState) => {
};

const updateTitle = (title, attributes) => {
if (typeof title === "string" && document.title !== title) {
document.title = title;
if (typeof title !== "undefined" && document.title !== title) {
document.title = Array.isArray(title) ? title.join("") : title;
}

updateAttributes(TAG_NAMES.TITLE, attributes);
Expand Down

0 comments on commit aad5457

Please sign in to comment.