Anne Stahl
Anne Stahl

Reputation: 121

DIVitis from React

I started working at a company who use REACT and I noticed that the HTML output has a TON of unnecessary divs. The developers tell me it's necessary for REACT, but I find it hard to believe that a modern framework/library/tool would force bad HTML practices on us. However, I can't seem to find any articles or references on this issue online. Is it really neccessary to wrap everything into a div? Why can't we wrap into the semantically correct element, like a p tag or nav, etc.? And finally, is this generally acceptable by the development community?

Upvotes: 2

Views: 316

Answers (2)

akaPorto
akaPorto

Reputation: 51

As the React documentation states:

React components can only render a single root node. If you want to return multiple nodes they must be wrapped in a single root.

That is the only requirement React has. Doesnt matter if the root node (element) is a div, ul, li, p, span, and so on - as a matter of fact, the root node should be the correct element instead of meaningless divs.

Sources:

React Docs on displaying data

We are developing a large React application in my company.

Upvotes: 1

Dmitriy Nevzorov
Dmitriy Nevzorov

Reputation: 6078

You can use any valid HTML5 tag in React.js as long as you return single DOM Node from your component render method. This is the only requirement.

List of supported tags and attributes

Upvotes: 5

Related Questions