我正在學習 react-native。我有一個我無法解決的問題。反應類組件中的狀態給我錯誤:意外令牌。但是功能組件中的 useState 可以正常作業。對不起我的語言。我來自蒙古。這是我的類和功能組件: react-native-class-component
反應原生功能組件
我該如何解決?
uj5u.com熱心網友回復:
在您的類組件中,您需要像這樣在建構式中宣告您的狀態
export default class Home extends Component{
constructor(props){
this.state = {}
}
render(){
return(
<View>
<Text></Text>
</View>
)
}
}
uj5u.com熱心網友回復:
您在類組件中宣告狀態的方式是錯誤的。它應該在您的建構式中。
export default class Home extends Component{
constructor(props){
this.state = {}
}
render(){
return(
…
)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/410574.html
標籤:
