React Web Component

React Web Component

Create component: Summary.js

Method 1, extend Component

import React from 'react'

class Summary extends React.Component {
  render() {
    const {ingredients, steps, title} = this.props
    return (
      <div className="summary">
        <h1>{title}</h1>
        <p>
          <span>{ingredients.length} Ingredients | </span>
          <span>{steps.length} Steps </span>
        </p>
      </div>
    )
  }
}

Method 2, stateless functional component

const Summary = ({ingredients, steps, title}) => {
  return <div>
    <h1>{title}</h1>
   <p>
     <span>{ingredients.length} Ingredients | </span>
     <span>{steps.length} Steps </span>
    </p>
  </div>
} 

or even more simpler:

const Summary = ({ingredients, steps, title}) =>
  <div>
    <h1>{title}</h1>
   <p>
     <span>{ingredients.length} Ingredients | </span>
     <span>{steps.length} Steps </span>
    </p>
  </div>

Use the component in main js: index.js

import React from 'react';
import ReactDOM from 'react-dom';
import Summary from './Summary';

ReactDOM.render(
  <Summary 
      title="Peanut Butter and Jelly"
      ingredients="peanut butter, jelly, bread"
      steps="spread peanut butter and jelly between bread" />, 
  document.getElementById('root')
);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • This project was bootstrapped with Create React App. Belo...
    unspecx阅读 5,241评论 0 2
  • 大傻问,你什么时候下课?我要给你打电话。 我说,好吧,我一般来说五点半下课,那你那个时候给我打吧。 下课后大傻的电...
    六六吖阅读 866评论 0 0
  • 阳光灿烂的时候, 出来走走, 心情也会跟着亮丽起来。 抬头看看蔚蓝的天空, 几朵白云轻轻飘过, 微笑着对你说: 生...
    会飞的兔宝宝阅读 334评论 0 1
  • 重写set方法,在cell里面赋值 // 公共属性,在控制器里面赋值 public var carListMode...
    旅途开发者阅读 1,264评论 0 0
  • 今天参观台北故宫博物馆,看到许多以前只能在书上看到的文物、字画。从商周到民国的全是真品…,大饱眼福,运动+...
    秋叶_ea4d阅读 75评论 0 0