转载请注明出处:王亟亟的大牛之路
先安利:https://github.com/ddwhan0123/Useful-Open-Source-Android
今天又加了几个疑难杂症哦!!
上一篇讲了属性,这一篇主要讲 State Style,给出上次的传送门,以便有更好的连贯性:http://blog.csdn.net/ddwhan0123/article/details/52238478
State 状态
在RN中用来描述对象的除了属性Props还有状态State,那么状态又是个什么东西呢?
There are two types of data that control a component: props and state. props are set by the parent and they are fixed throughout the lifetime of a component. For data that is going to change, we have to use state.
In general, you should initialize state in the constructor, and then
call setState when you want to change it.
这一段英文很罗嗦但是我们看下关键的信息
1 .props是在父组件中指定,一经指定,在被指定的生命周期中则不再改变
2 .对于需要改变的数据,我们需要使用

本文探讨了React Native中的State和Style。State是组件中可变的数据,通常在构造函数中初始化,并通过setState方法更新。文章通过一个文字隐藏显示的例子说明了State的使用。而Style方面,虽然与Web CSS相似,但存在一些差异。RN允许组件拥有多个样式,后面的样式会覆盖前面的,实现了样式继承的概念。
最低0.47元/天 解锁文章
1万+





