【发布时间】:2017-11-29 21:15:48
【问题描述】:
我正在为学校做一个项目并使用 react native。诚然,我在 JavaScript 方面是新手。我不明白为什么在React Navigation tutorial 他们使用 const 类型。
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
<Text>Hello, Chat App!</Text>
<Button
onPress={() => navigate('Chat')}
title="Chat with Lucy"
/>
</View>
);
}
}
所以我的问题是: const 类型用于const { navigate } = this.props.navigation; 是否有特殊或重要的原因
【问题讨论】:
-
为什么不呢?
navigate函数不会以任何方式改变。它只是一个简写,所以你可以写navigate('Chat')而不是完整的标识符。
标签: javascript react-native types stack-navigator