Return multiple React elements in a method without a wrapper element

前端 未结 10 872
南方客
南方客 2020-12-16 13:06

I\'m trying to return multiple React elements from a helper method. I could solve it simply by moving around some code, but I\'m wondering if there\'s a cleaner way to solve

10条回答
  •  囚心锁ツ
    2020-12-16 13:40

    It's not currently possible to do this without some sort of workaround like wrapping everything in another component, since it ends up with the underlying React code trying to return multiple objects.

    See this active Github issue where support for this is being considered for a future version though.


    Edit: You can now do this with Fragments in React 16, see: https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html

提交回复
热议问题