Reputation: 121
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
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:
We are developing a large React application in my company.
Upvotes: 1
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