[React Fundamentals] State Basics

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>
)
}
}
上一篇:虚拟主机无法使用fsockopen操作处理方法


下一篇:20165301 预备作业三:Linux安装及命令入门