简体   繁体   English

React Native ReferenceError 找不到变量

[英]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.

相关问题 ReferenceError: 找不到变量: False - React Native (Hookstate) - ReferenceError: Can't find variable: False - React Native (Hookstate) REACT-NATIVE - abcjs - ReferenceError:找不到变量:元素 - REACT-NATIVE - abcjs - ReferenceError: Can't find variable: Element ReferenceError:找不到变量:hasLocationPermission - React Native - ReferenceError: Can't find variable: hasLocationPermission - React Native 使用 Expo “ReferenceError:找不到变量:警报”反应本机 - React Native with Expo “ReferenceError: Can't find variable: Alert” ReferenceError:找不到变量:导航 [React Native] - ReferenceError: Can't find variable: navigation [React Native] ReferenceError:找不到变量:在本机反应中导航 - ReferenceError: Can't find variable: navigation in react native React Native Formik 与 react redux 一起使用(参考错误:找不到变量:标题) - React Native Formik use with react redux (ReferenceError: Can't Find Variable: title) 自定义字体 React-Native,[未处理的承诺拒绝:ReferenceError:找不到变量:ExpoFontLoader] - Custom font React-Native, [Unhandled promise rejection: ReferenceError: Can't find variable: ExpoFontLoader] react-native [iOS] RCTAssert RCTFormatError 165 ReferenceError:找不到变量:typeAnnotation - react-native [iOS] RCTAssert RCTFormatError 165 ReferenceError: Can't find variable: typeAnnotation ReferenceError 找不到变量:Image - React Native,create-expo-app。 无法使用 Image() 创建 HTMLImageElement - ReferenceError Can't find variable: Image - React Native, create-expo-app. Can't create an HTMLImageElement with Image()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM