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的更多相关文章

  1. [React] React Fundamentals: State Basics

    State is used for properties on a component that will change, versus static properties that are pass ...

  2. react 中state与props

    react 中state与props 1.state与props props是只读属性,只有在组件被实例化的时候可以赋值,之后的任何时候都无法改变该值.如果试图修改该值时,控制台会报错 only re ...

  3. [React] Update State in React with Ramda's Evolve

    In this lesson we'll take a stateful React component and look at how we can refactor our setState ca ...

  4. React给state赋值的两种写法

    如果你看过React的官方文档,就会对怎么给局部state赋值有一定的了解.如下代码: class Test extends React.Component { constructor(props) ...

  5. React:Lifting State Up

    在学习React的组件的时候,我也好奇组件间需要共享状态或通信的时候,React是如何处理的.在文档的QUICK START的提到Lifting State Up(状态提升),并不是什么新鲜东西.只是 ...

  6. Recoil & React official state management

    Recoil & React official state management Redux Recoil.js https://recoiljs.org/ A state managemen ...

  7. React & update state with props & Object.assign

    React & update state with props & Object.assign Object.assign({}, oldObj, newObj) https://re ...

  8. 七天接手react项目 —— state&事件处理&ref

    state&事件处理&ref 在 react 起步 一文中,我们学习了 react 相关知识:jsx.组件.props.本篇将继续研究 state.事件处理和ref. state St ...

  9. [React Fundamentals] Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

随机推荐

  1. 大四实习准备4_java内部类

    2015-4-30 [昨天又可耻地休息了一天,懒劲比较大啊.跟懒劲有直接关系,这几天对幸福的感知也黯淡了,对未来的幸福不是那么渴望了.表现在对亲情和爱情上. 我想生活的本意是积极进取.茁壮生长并时常感 ...

  2. 微软 Virtual studion Code

    在 Build 2015 大会上,微软除了发布了 Microsoft Edge 浏览器和新的 Windows 10 预览版外,最大的惊喜莫过于宣布推出免费跨平台的 Visual Studio Code ...

  3. NFA和DFA区别

    一个数据块的访问时间等于寻道时间.旋转延迟时间和数据传输时间三者之和: NFA和DFA区别: 一个状态如A,遇0可以转换到下一个状态B或C,因为选择多所以不确定,因此为不确定的有限自动机: 一个状态还 ...

  4. Linux环境变量的设置和查看方法

    1. 显示环境变量HOME $ echo $HOME /home/redbooks 2. 设置一个新的环境变量hello $ export HELLO="Hello!" $ ech ...

  5. 【JMeter】ant+jmeter生成html报告

    源博文来自于  http://my.oschina.net/hellotest/blog/517518 主要应用于接口的回归或者性能的简单查看功能.操作为先在jmeter中写好测试计划,保存为jmx文 ...

  6. opencv 在工业中的应用:圆孔定位

    在工业中产品或者夹具上经常有圆形孔,我们可以利用这些孔来对产品或者夹具进行定位.我用OPENCV写了个DEMO 程序,介绍如下: (1)首先点击打开图像按钮打开一幅图像 (2)进行一些参数设置 (3) ...

  7. MFC 文件操作

    MFC中文件的建立 在操作系统中,文件是放在一定的目录下,在创建以及操作文件以前,我们要查看文件要保存的目录有没有存在,如果不存在要创建.这就要用到GetFileAttributes()和Create ...

  8. 4.1Reduction模型

    1. Reduction Reduction是一种广泛使用的计算模型,特别是在并行计算领域.简单地来说,Reduction就是一系列的划分(Partition)和汇总(Summarize)操作的集合: ...

  9. 自编译安装nginx

    1. 下载nginx,并解压 http://nginx.org/ 2. 下载health check模块 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 1 ...

  10. prefuse学习(一)用非数据库连接和xml的方式读入数据

    prefuse正常的数据源需要从ConnectionFactory中生产出来,但是如果平时不想用里面给的方法得到数据,就需要手动创造Graph里面所需要的内容两个Table 下面是我自己写的从文件中读 ...