[英]React Native ReferenceError Can't find variable
Have been going through the documentation in https://facebook.github.io/react-native/docs/text.html .一直在阅读 https://facebook.github.io/react-native/docs/text.html中的文档。 Its not clear how to link the reference between the two classes.
目前尚不清楚如何链接两个类之间的引用。 I am trying to use the tag instead of and it this gives no reference found error.
我正在尝试使用标签而不是它,这没有找到参考错误。
Code:代码:
import React, {Component} from 'react';
import {
Text,
View,
AppRegistry,
} from 'react-native';
class MyAppHeaderText extends Component {
render() {
return(
<MyAppHeader>
<Text style={{fontSize:20}}>
{this.props.children}
</Text>
</MyAppHeader>
)
}
}
class Test2 extends Component {
constructor(props){
super(props);
this.state = {
mainText: 'This is Bird',
subText : 'Not dino'
}
}
render() {
return(
<View>
{/* <Text>
{this.state.mainText}
{this.state.subText}
</Text> */}
<MyAppHeaderText>
<MyAppHeader>
{this.state.mainText}
{this.state.subText}
</MyAppHeader>
</MyAppHeaderText>
</View>
)
}
}
export default MyAppHeaderText;
AppRegistry.registerComponent('AwesomeProject',() => Test2);
Error:错误:
ReferenceError: Can't find variable: MyAppHeader
ReferenceError:找不到变量:MyAppHeader
This error is located at: in Test2 (at renderApplication.js:35) in RCTView (at View.js:113) in View (at AppContainer.js:102) in RCTView (at View.js:113) in View (at AppContainer.js:122) in AppContainer (at renderApplication.js:34)
此错误位于: 在 Test2 (at renderApplication.js:35) 在 RCTView (at View.js:113) 在 View (at AppContainer.js:102) 在 RCTView (at View.js:113) 在 View (at AppContainer.js:122) 在 AppContainer (在 renderApplication.js:34)
As Derek mentioned, 正如德里克所说,
you have never defined
MyAppHeader
, therefore you will get error.你从未定义过
MyAppHeader
,因此你会收到错误。
You could delete all <MyAppHeader></MyAppHeader>
in your project, and it should work! 您可以删除项目中的所有
<MyAppHeader></MyAppHeader>
,它应该可以正常工作!
Otherwise you will need to defined MyAppHeader Component to make it works. 否则,您需要定义MyAppHeader组件才能使其正常工作。
Clearly post for React Components Components and Props - React 显然发布React Components 组件和道具 - React
Hope it will help. 希望它会有所帮助。
That way you'il do what you want. 那样你就可以做你想做的事。
class Test2 extends Component {
constructor(props){
super(props);
this.state = {
mainText: 'This is Bird',
subText : 'Not dino'
}
}
render() {
return(
<View>
{/* <Text>
{this.state.mainText}
{this.state.subText}
</Text> */}
<MyAppHeaderText>
{this.state.mainText}
{this.state.subText}
</MyAppHeaderText>
</View>
)
}
}
<Checkbox disabled='true' checked='true'/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.