博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React] React Fundamentals: State Basics
阅读量:5048 次
发布时间:2019-06-12

本文共 1257 字,大约阅读时间需要 4 分钟。

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.

 

Properties vs. State

When you think of properties, you should be thinking of component initialisation. When you think of state, you should think of an internal data-set which affects the rendering of components.

 

Setting Initial State:

This is done by defining a method called getInitialState() and returning an object.

 

Setting State:

Setting state should only be done from inside the component. As mentioned, state should be treated as private data, but there are times when you may need to update it. setState()

 

Replacing State:

It’s also possible to replace values in the state by using the replaceState()method.

/** * @jsx React.DOM */  var InterfaceComponent = React.createClass({  getInitialState : function() {    return {      first : "chris",      last  : "pitt"    };  },  handleClick : function() {    this.replaceState({      first : "bob"    });  },  render : function() {    return 
hello { this.state.first + " " + this.state.last }
; }});

 

    
React Lesson 3: state

 

More: 

 

转载于:https://www.cnblogs.com/Answer1215/p/4361631.html

你可能感兴趣的文章
Spring Cloud微服务笔记(五)Feign
查看>>
C语言键盘按键列表
查看>>
Codeforces Round #374 (Div. 2)
查看>>
oracle数据类型
查看>>
socket
查看>>
Vue中使用key的作用
查看>>
二叉索引树 树状数组
查看>>
日志框架--(一)基础篇
查看>>
Java设计模式之原型模式
查看>>
Spring学习(四)-----Spring Bean引用同xml和不同xml bean的例子
查看>>
哲理故事与管理之道(20)-用危机激励下属
查看>>
关于源程序到可运行程序的过程
查看>>
wepy的使用
查看>>
转载:mysql数据库密码忘记找回方法
查看>>
scratch少儿编程第一季——06、人在江湖混,没有背景怎么行。
查看>>
面向对象1
查看>>
在ns2.35中添加myevalvid框架
查看>>
【贪心+DFS】D. Field expansion
查看>>
为什么要使用href=”javascript:void(0);”
查看>>
二进制文件的查看和编辑
查看>>