How to avoid extra wrapping
in React?

前端 未结 10 1013
孤独总比滥情好
孤独总比滥情好 2020-12-02 12:04

Today I have started learning ReactJS and after an hour faced with the problem.. I want to insert a component which has two rows inside a div on the page.A simplified exampl

10条回答
  •  死守一世寂寞
    2020-12-02 12:15

    I know this question has been answered, you can of course use React.Fragment which doesn't create a node but let's you group stuff like a div.

    Additionally if you want to have fun you can implement (and learn lots of things) a React mode that removes the extra div's and for this I really want to share a great video on how you can do it on the react code base itself.

    https://www.youtube.com/watch?v=aS41Y_eyNrU

    This is of course not something that you would do in practice but it's a good learning opportunity.

提交回复
热议问题