您的位置:首页 > Web前端 > React

[React Fundamentals] State Basics

2016-08-15 03:29 246 查看
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>
)
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: