Component
可以在Component的Constructor
中設置成員變量
// 構造
constructor(props) {
super(props);
// 初始狀態
this.state = {
switchOn: false,
selectedLanguage: 'java',
...
key:value
};
}
在render()
中的各個組件中的屬性中,可以使用
this.state.key
獲得該key的值,可以使用
this.setState({key:value});
設置屬性值。
props
你可以使用
<Demos navigator={navigator}/>
把相關的數據傳到Demos
這個視圖中,然后在Demos
中獲取到navigator
這個屬性
<TouchableWithoutFeedback
onPress={()=>{
this.props.navigator.push({index:3});
}
}>