Vys*_*ish 5 javascript android react-native
已经浏览过https://facebook.github.io/react-native/docs/text.html中的文档。目前尚不清楚如何在两个类之间链接引用。我正在尝试使用标记代替它,这没有找到参考错误。
代码:
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);
Run Code Online (Sandbox Code Playgroud)
错误:
ReferenceError:找不到变量:MyAppHeader
此错误位于:View(at)的RCTView(at View.js:113)的RCTView(AppContainer.js:102)中的Test2(renderApplication.js:35)中AppContainer中的AppContainer.js:122)(位于renderApplication.js:34)
正如德里克所说,
您从未定义过
MyAppHeader,因此会出错。
您可以删除<MyAppHeader></MyAppHeader>项目中的全部,它应该可以工作!
否则,您将需要定义MyAppHeader组件以使其起作用。
明确发布React Components的组件和道具-React
希望它会有所帮助。
| 归档时间: |
|
| 查看次数: |
10773 次 |
| 最近记录: |