2017-11-29 4 views
0

https://facebook.github.io/react-native/docs/text.html의 설명서를 읽었습니다. 두 클래스 사이의 참조를 연결하는 방법이 명확하지 않습니다. 대신에 태그를 사용하려고하는데 참조가 발견되지 않습니다.React Native ReferenceError 변수를 찾을 수 없습니다.

코드 :

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); 

오류 : 당신은 당신의 프로젝트의 모든 <MyAppHeader></MyAppHeader>를 삭제할 수 있습니다, 그것은 작동합니다

you have never defined MyAppHeader , therefore you will get 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)

+0

글쎄, 코드 내 어디에서나'MyAppHeader'를 정의한 적이 없습니다. –

답변

0

데릭이 언급 한 바와 같이,!

그렇지 않으면 MyAppHeader 구성 요소가 작동하도록 정의해야합니다.

희망이 있으면 도움이 될 것입니다.

관련 문제