Skip to content

<title> problem: A title element received an array with more than 1 element as children #38256

Discussion options

You must be logged in to vote

Hi,

The warning is because when you do:

const Home: NextPage = () => {
  const world = "World";
  return (
    <div>
      <span>Hello {world} foo</span>
    </div>
  );
};

React renders:

<div><span>Hello <!-- -->World<!-- --> foo</span></div>

That's a div with a span child, with 0 children elements, but 5 nodes as children. There's a subtle difference between elements and nodes. Here's a handy video.

The 5 nodes are, text, comment, text, comment, text. The same is happening to your title element.

Do this instead:

const Home: NextPage = () => {
  const world = "World";
  const message = `Hello ${world} foo`;
  return (
    <div>
      <span>{message}</span>
    </div>
  );
};

Which outputs:

Replies: 9 comments 21 replies

Comment options

You must be logged in to vote
13 replies
@cdx111
Comment options

@1mehdifaraji
Comment options

@zohaibasghar
Comment options

@pajarrahmansyah
Comment options

@Asylcreek
Comment options

Answer selected by florianwalther-private
Comment options

You must be logged in to vote
6 replies
@icyJoseph
Comment options

@discoverlance-com
Comment options

@talhaa99
Comment options

@t-lock
Comment options

@discoverlance-com
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@icyJoseph
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@data-miner00
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet