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

[React Fundamentals] Owner Ownee Relationship

时间:2016-08-15 06:39:46      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

The owner-ownee relationship is used to designate a parent-child relationship with React components as it differs from the DOM relationship.

 

import React from ‘react‘;

export default class App extends React.Component {
    constructor(){
        super(); //This is going to give us our context for this within our component
        this.update = this.update.bind(this);
        this.state = {
            txt: ‘State‘,
            count: 1
        }
    }
    update(e){
        this.setState({
            txt: e.target.value
        })
    }
    render() {
        return (
            <div>
                <Widget txt={this.state.txt} update={this.update}></Widget>
                <Widget txt={this.state.txt} update={this.update}></Widget>
            </div>

        )
    }
}

// "Widget" must be capitalized
const Widget = (props) => {
    return (
        <div>
            <input type="text" onChange={props.update} />
            <span>Hello {props.txt}</span>
        </div>
    )
}

 

[React Fundamentals] Owner Ownee Relationship

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5771546.html

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