首页 > 其他 > 详细

[React Fundamentals] State Basics

时间:2016-08-15 06:37:40      阅读:147      评论:0      收藏:0      [点我收藏+]

State is used for properties on a component that will change, versus static properties that are passed in. This lesson will introduce you to taking input within your React components.

 

Unlike props, which are meant to be passed into our component as static values or methods, state is a collection of values that‘s meant to be managed by our component itself. 

 

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.state = {
            txt: ‘State‘,
            count: 1
        }
    }
    update(e){
        this.setState({
            txt: e.target.value
        })
    }
    render() {
        return (
            <div>
                <input type="text" onChange={this.update.bind(this)} />
                <span>Hello {this.state.txt}</span>
            </div>
        )
    }
}

 

[React Fundamentals] State Basics

原文:http://www.cnblogs.com/Answer1215/p/5771544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!