Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  131] [ 4]  / answers: 1 / hits: 42451  / 7 Years ago, wed, november 29, 2017, 12:00:00

Have been going through the documentation in 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



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)



More From » android

 Answers
21

As Derek mentioned,




you have never defined MyAppHeader, therefore you will get error.




You could delete all <MyAppHeader></MyAppHeader> in your project, and it should work!



Otherwise you will need to defined MyAppHeader Component to make it works.



Clearly post for React Components Components and Props - React



Hope it will help.


[#55808] Sunday, November 26, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseb

Total Points: 252
Total Questions: 96
Total Answers: 106

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
analiseb questions
;