Return multiple elements inside React.render()

后端 未结 5 1151
渐次进展
渐次进展 2020-12-04 21:29

I am new in react and I encountered with this problem:

render: function(){
    return (
        

Account

5条回答
  •  庸人自扰
    2020-12-04 22:11

    React.render is a JavaScript function returning the DOM elements. Since in JavaScript, functions cannot return multiple expressions, so we can't return multiple elements in React. The function returns the first expression immediately after the "return" keyword, and then the function dies. That's why we are able to do this:

    if(1) { return 1 } return 2

提交回复
热议问题