React-helmet: Using provided example - Uncaught Error: Helmet expects a string as a child of <title>.

Created on 3 May 2017  路  9Comments  路  Source: nfl/react-helmet

Using the first example in the readme.md

import React from "react";
import {Helmet} from "react-helmet";

class Application extends React.Component {
    return (
        <div className="application">
            <Helmet>
                <meta charSet="utf-8" />
                <title>My Title</title>
                <link rel="canonical" href="http://mysite.com/example" />
            </Helmet>
            ...
        </div>
    );
};

I get:

Uncaught Error: Helmet expects a string as a child of <title>. Did you forget to wrap your children in braces? ( <title>{``}</title> ) Refer to our API for more information.
at HelmetWrapper.warnOnInvalidChildren

Even if I change it to

<title>{'My Title'}</title>

I get the same issue

Any ideas?

Most helpful comment

I encountered similar problem with following code:

<Helmet>
    <title>Product - { item.name }</title>
</Helmet>

Fixed using string literal

<Helmet>
    <title>{ `Product - ${ item.name }` }</title>
</Helmet>

All 9 comments

Our unit tests definitely test this case. My Title should be a string. Hmmm.... What's your version of React?

I'm also getting this, though if I use <Helmet title="My Title"> instead it works. Running React 15.5.4.

Some elements work such as meta and link, but this doesn't for e.g. (from README):

<script src="http://include.com/pathtojs.js" type="text/javascript" />
Error: Helmet expects a string as a child of <script>. Did you forget to wrap your children in braces? ( <script>{``}</script> ) Refer to our API for more information.
    at HelmetWrapper.warnOnInvalidChildren

I'm using hyperx instead of JSX.

I encountered similar problem with following code:

<Helmet>
    <title>Product - { item.name }</title>
</Helmet>

Fixed using string literal

<Helmet>
    <title>{ `Product - ${ item.name }` }</title>
</Helmet>

yep just ran into this as well. Above solution is a good workaround.

This is rather annoying when trying to do internationalization. Just allow a node.

Would love it if nodes were allowed as well. It just seems a bit silly at the moment. It's not that much more, but the first is much easier to read.

Right now, I have to turn this:

<Helmet>
  <title>Default Title{subtitle && `: ${subtitle}`}</title>
</Helmet>
````

Into this:


{subtitle ? <code>Default Title: ${subtitle}</code> : <code>Default Title</code>}

````

Just like OP I'm getting these warnings even though all my titles are explicitly wrapped as strings. This is more annoying than anything but would like to see this fixed.

[email protected]

@mikedpad or you can write it, if you prefer, like so:

<Helmet>
  <title>{`Default Title${ subtitle ? ': '+subtitle : '' }`}</title>
</Helmet>

I encountered similar problem with following code:

<Helmet>
    <title>Product - { item.name }</title>
</Helmet>

Fixed using string literal

<Helmet>
    <title>{ `Product - ${ item.name }` }</title>
</Helmet>

Thank you! Your suggestion worked perfect!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tinynumbers picture tinynumbers  路  5Comments

sneridagh picture sneridagh  路  4Comments

olalonde picture olalonde  路  3Comments

bradbarrow picture bradbarrow  路  4Comments

aequasi picture aequasi  路  3Comments