[英]Looks like hoisting is working in React Native with const
我注意到一個有趣的事情在本地反應。 我認為const和let不支持在ES6中提升。 如何在其定義之上使用const 樣式 ?
render() {
const { repos } = this.state;
const reposList = repos.map((rep, index) => {
return (
<Text>{rep.name}</Text>
)
});
return (
<View style={styles.container}> <-- styles should not be defined
{reposList}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
是因為React Native中的提升機制嗎?
如果在類中定義了渲染,則只定義該類未執行,以便它可以看到您在其下創建的樣式。 它並沒有真正起吊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.