码迷,mamicode.com
首页 > 其他好文 > 详细

[React] Use React Fragments to make your DOM tree cleaner

时间:2018-01-30 12:55:07      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:foo   ret   structure   out   efault   alt   without   rom   head   

In this lesson, we will look at Fragments and how they are useful in achieving a cleaner DOM structure without additional empty div elements.

 

const HeaderFooter = () => {
  return (
    <div>
      <div>
        header
      </div>
      <div>
        footer
      </div>
    </div>
  );
}

技术分享图片

 

import React, { Component, Fragment } from ‘react‘;
import {render} from ‘react-dom‘
const HeaderFooter = () => {
  return (
    <Fragement>
      <div>
        header
      </div>
      <div>
        footer
      </div>
    </Fragment>
  );
}

export default class App extends Component {
  render() {
    return (
      <div>
        <HeaderFooter />
      </div>
    );
  }
}

render(<App />, document.getElementById(‘root‘));

技术分享图片

[React] Use React Fragments to make your DOM tree cleaner

标签:foo   ret   structure   out   efault   alt   without   rom   head   

原文地址:https://www.cnblogs.com/Answer1215/p/8382884.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!