react-native的props使用
props
// 使用props传值
<View style={{marginTop: 20}}>
<CommonCell title="扫一扫"/>
</View>
// 在组件中设置默认props值
static defaultProps = {
title: '', // 标题
isOn: false, // 是否展示开关
};
// 获取到props值
this.props.title
state
// 在构造方法中初始化
constructor(props) {
super(props);
// 设置state的值
this.state = {
isOn: false,
};
}
// 获取state值
this.state.isOn
设置state的值
this.setState({
isOn: true
}
)};