admin管理员组文章数量:1277301
I would like to create an app using semantic html. The app will have header, navigation, main area, footer, and side bar.
The app uses react, so there is an index.js and index.html. This is where react renders an element into the root DOM node.
index.js
render(<App />, document.getElementById('root'))
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Title</title>
</head>
<body>
//<div id="root"></div>
// <main id="root"></main>
// <section id="root"></section>
</body>
</html>
I expect the app to produce something similar to:
<some root node>
<header>
<nav>
<main>
<aside>
<footer>
Since React requires a root node, what element type should that be (what is the most semantically correct)? The root node is inside index.html, therefore a fragment will not solve the problem. I've mented out a few ideas inside index.html which are div, main, and section.
I would like to create an app using semantic html. The app will have header, navigation, main area, footer, and side bar.
The app uses react, so there is an index.js and index.html. This is where react renders an element into the root DOM node.
index.js
render(<App />, document.getElementById('root'))
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Title</title>
</head>
<body>
//<div id="root"></div>
// <main id="root"></main>
// <section id="root"></section>
</body>
</html>
I expect the app to produce something similar to:
<some root node>
<header>
<nav>
<main>
<aside>
<footer>
Since React requires a root node, what element type should that be (what is the most semantically correct)? The root node is inside index.html, therefore a fragment will not solve the problem. I've mented out a few ideas inside index.html which are div, main, and section.
Share Improve this question edited Aug 6, 2019 at 20:23 Nathan Hall asked Aug 6, 2019 at 20:09 Nathan HallNathan Hall 4072 gold badges8 silver badges17 bronze badges 4-
On their website they use
<div>
s, so I'd say go with that. – Luca Kiebel Commented Aug 6, 2019 at 20:11 -
Maybe
<main></main>
? w3schools./tags/tag_main.asp – Unixmonkey Commented Aug 6, 2019 at 20:12 -
3
@Unixmonkey main should ideally not contain repeated content like side bars, navigations, etc... i would stick with the goold old
<div />
as root node – Turtlefight Commented Aug 6, 2019 at 20:13 - @Turtlefight Agree. Thank you! – Nathan Hall Commented Aug 7, 2019 at 15:29
4 Answers
Reset to default 7<main>
is supposed to relate to the dominant part of the content. If you wish to have navigation, header and/or sidebar and things like that it seems more apropriate to use a div for the App and use the <main>
tag for the main content on the page.
It doesn't really make a difference but the official documentation uses a <div>
You can aldo uso document.body
if you prefer. It does not have a particular relevance if you have only a SPA in your page.
You can use main tag for the root and after that use section tag for the respective sections.
本文标签: javascriptWhat html element to use for react root dom nodeStack Overflow
版权声明:本文标题:javascript - What html element to use for react root dom node? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741290706a2370531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论