question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not multi components was rendered to body of document?

See original GitHub issue

Hi, there

I’m rewriting my blog using preact, and I found returning multi components to document, console occurs error: nents/app.js: Adjacent JSX elements must be wrapped in an enclosing tag My code is below:

export default class App extends Component { render() { return ( <Header/> <Content/> ); } } Before all components was rendered, it must be wrapped <div> or other elements?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
developitcommented, Nov 17, 2017

It’s on the ToDo list, but extremely difficult given Preact’s current design.

6reactions
gaearoncommented, Nov 29, 2017

Note: In React 16, a new feature was added where you can return an array of elements without enclosing them in the single tag but I am not sure whether that feature exists in Preact or not.

I’d mention that React 16.2 adds a special React.Fragment export with slightly different semantics from vanilla arrays. React fragments can be keyed which is handy for returning “tuples” from map.

The plan is to have JSX compile <> to <React.Fragment>, but there’s a Babel pragma you can change (e.g. Preact could provide Preact.Fragment instead).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rendering components directly warning - Stack Overflow
The warning you are getting comes when you try to render directly within document.body. However, the code in your index.js is the correct...
Read more >
7 The global structure of an HTML document - W3C
Certain HTML elements that may appear in BODY are said to be "block-level" while others are "inline" (also known as "text level"). The...
Read more >
Advanced Features: Custom `Document` - Next.js
A custom Document can update the <html> and <body> tags used to render a Page. This file is only rendered on the server,...
Read more >
ASP.NET Core Blazor layouts - Microsoft Learn
Every folder of an app can optionally contain a template file named ... The Episodes component is rendered where @Body appears in the ......
Read more >
markdown-to-jsx - npm
</Markdown>, document.body); /* renders: <h1>Hello world!</h1> */. * NOTE: JSX does not natively preserve newlines in multiline text.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found