16. react - Fragment

1. Fragment : 可以理解为空标签。 类似与 微信小程序的 <block>

2. 实例:

import { Fragment } from 'react'

class LI extends React.Component {
  constructor (props) {
    super(props)
  }
  render () {
    console.log(this.props.lists)
    return(
      <Fragment>
        {
          this.props.lists.map(i => (
            <li key={i}>{ i }</li>
          ))
        }
      </Fragment>
    )
  }
}

class UL extends React.Component {
  constructor(props) {
    super(props)
  }

  render () {
    const lists = [1,2,3,4]
    return(
      <ul>
        <LI lists={lists}></LI>
      </ul>
    )
  }
}
ReactDOM.render(
  <UL />,
  document.getElementById('root')
)

以上代码的渲染结果: 

 

posted @ 2020-06-17 15:22  monkey-K  阅读(140)  评论(0编辑  收藏  举报