[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.
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] Owner Ownee Relationship
- [React Fundamentals] Accessing Child Properties
- [React Fundamentals] Using Refs to Access Components
- [React Fundamentals] Composable Components
- [React Fundamentals] Component Lifecycle - Mounting Basics
- [React Fundamentals] Component Lifecycle - Mounting Usage
- [React] React Fundamentals: State Basics
- [React Fundamentals] Component Lifecycle - Updating
- [React Fundamentals] Development Environment Setup
- [React Fundamentals] Introduction to Properties
- React 定义组件的参数对象
- react-native中使用到的样式属性
- react-native + redux 实践
- React Native 真机调试
- 从性能角度看react组件拆分的重要性
- React使用
- react js踩坑之路(一)
- React Js string字符串转换为html dom
- react+webapck多页面(multipage)程序
- react-redux原理分析