我在学习反应本土化。我有个问题我解决不了。react类组件中的状态给出了错误:意外令牌。但是功能组件中的useState工作得很好。对不起我的语言。我来自蒙古。下面是我的类和函数组件:反应-本机级组件
我该怎么解决呢?
发布于 2022-01-14 05:44:12
在类组件中,您需要在构造函数中声明状态,如下所示
export default class Home extends Component{
constructor(props){
this.state = {}
}
render(){
return(
<View>
<Text></Text>
</View>
)
}
}
发布于 2022-01-14 05:49:01
在类组件中声明状态的方式是错误的。它应该在构造函数中。
export default class Home extends Component{
constructor(props){
this.state = {}
}
render(){
return(
…
)
}
}
https://stackoverflow.com/questions/70706307
复制相似问题