Why are Fragments in React 16 better than container divs?

后端 未结 6 1714
陌清茗
陌清茗 2020-12-22 15:39

In React 16.2, improved support for Fragments has been added. More information can be found on React\'s blog post here.

We are all familiar with the fol

6条回答
  •  孤城傲影
    2020-12-22 16:26

    As per the reactjs.org docs most important needs of instead of div's are to avoid breaking HTML semantics. When we use div's instead of we break the HTML semantics.

    To know more about html semantics. please click and also there are cases where if you use div's instead of Fragments it will be invalid html, for example look at this code:

    class Columns extends React.Component {
      render() {
        return (
          
    Hello World
    ); } }
    Hello World

    Fragments solve this problem.

提交回复
热议问题