简体   繁体   English

为什么我得到“undefined不是一个对象(评估PropTypes.shape)”?

[英]Why am I getting “undefined is not an object (evaluating PropTypes.shape)”?

Whenever I try to run my iOS simulator, I'm getting that error. 每当我尝试运行我的iOS模拟器时,我都会收到该错误。 All modules are installed, file path to my picture is correct, no errors being thrown within my IDE except for the one that's appearing in my simulator. 所有模块都已安装,我的图片的文件路径是正确的,除了我的模拟器中出现的错误外,我的IDE中没有错误。 Picture below of error. 图片下面的错误。

错误图片

Here's Login.js : 这是Login.js

import React, {Component} from 'react';
import {StyleSheet, TextInput, Text, TouchableOpacity, KeyboardAvoidingView} from 'react-native';

class Login extends Component {
    onButtonPress() {
        this.props.navigator.push({
            id: 'CreateAccount'
        });
    }

    render() {
        return(
            <KeyboardAvoidingView behavior={"padding"} style={styles.container}>
                    <TextInput
                        style={styles.input}
                        returnKeyType={"next"}
                        keyboardType={"email-address"}
                        autoCorrect={false}
                        placeholder={"Email"}
                    />

                    <TextInput
                        style={styles.input}
                        returnKeyType={"go"}
                        placeholder={"Password"}
                        secureTextEntry
                    />

                    <TouchableOpacity>
                        <Text style={styles.loginAndCA}>Login</Text>
                    </TouchableOpacity>

                    <TouchableOpacity onPress={this.onButtonPress.bind(this)}>
                        <Text style={styles.loginAndCA}>Create Account</Text>
                    </TouchableOpacity>
            </KeyboardAvoidingView>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        padding: 20 // Length of text input boxes.
    },

    input: {
        backgroundColor: '#DAE5FF',
        padding: 20,
        paddingHorizontal: 15,
        marginBottom: 10,
        borderRadius: 15
    },

    loginAndCA: {
        fontSize: 40,
        textAlign: 'center',
        color: 'white',
        fontFamily: 'Bodoni 72 Smallcaps',
        paddingHorizontal: 10
    }
});

export default Login;

Here's BackGround.js : 这是BackGround.js

import React, {Component} from 'react';
import {StyleSheet, Image, View, Text} from 'react-native';
import Login from './Login';

class BackGround extends Component {
    render() {
        return(
            <View style={styles.first}>
                <Image style={styles.container} source={require('../pictures/smoke.jpg')}>
                    <View style={styles.second}>
                         <View>
                            <Text style={styles.title}>My App</Text>
                         </View>
                        <Login/>
                    </View>
                </Image>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        width: null,
        height: null,
        backgroundColor: 'rgba(0,0,0,0)'
    },

    first: {
        flex: 1
    },

    second: {
       paddingTop: 290 // Moves both <TextInput> boxes down.
    },

    title: {
        fontSize: 34,
        textAlign: 'center',
        justifyContent: 'center',
        flexDirection: 'row',
        fontFamily: 'Bodoni 72'
    }

    // movementTitle: {
    //     paddingBottom: 34
    // }
});

export default BackGround;

Here's CreateAccount.js : 这是CreateAccount.js

import React, {Component} from 'react';
import {Text} from 'react-native';

class CreateAccount extends Component {
    render() {
        return(
            <Text>Must get to this page</Text>
        );
    }
}

export default CreateAccount;

Here's index.ios.js : 这是index.ios.js

import React, {Component} from 'react';
import {View, StyleSheet, AppRegistry} from 'react-native';
import {Navigator} from 'react-native-deprecated-custom-components';
import BackGround from './components/BackGround';
import Login from "./components/Login";
import CreateAccount from "./components/CreateAccount";

export default class App extends Component {
    render() {
        return(
            <View style={styles.back}>
              <BackGround/>
              <Navigator
                  initialRoute={{id: 'Login'}}
                  renderScene={this.navigatorRenderScene}
              />
            </View>
        );
    }

    navigatorRenderScene() {
        _navigator = navigator;
        switch(route.id) {
            case 'Login':
                return (<Login navigator={navigator} title="Login"/>);
            case 'CreateAccount':
                return (<CreateAccount navigator={navigator} title="Create Account" />);
        }
    }
}

const styles = StyleSheet.create({
    back: {
        flex: 1
    }
});

AppRegistry.registerComponent('dendroApp', () => dendroApp);

React recently removed PropTypes from their core library as of React 15.5. React最近从React 15.5中删除了其核心库中的PropTypes。

Add the line 添加行

import PropTypes from 'prop-types';

And call your proptypes directly from that. 并直接从中调用你的proptypes。

It seems PropTypes is undefined. 似乎PropTypes未定义。 I don't see it declared anywhere in your code. 我没有看到它在你的代码中的任何地方声明。 You have to import it via a separate module as shown in the documents: PropTypes. 您必须通过单独的模块导入它,如文档中所示: PropTypes。

Update: 更新:

Perhaps a library you are using is using the now deprecated/non-supported React.PropTypes. 您正在使用的库可能正在使用现已弃用/不受支持的React.PropTypes。 I recommend using a more up to date library or actually going into the library and updating the package so it uses the new PropTypes from the separate package instead of React.PropTypes. 我建议使用更新的库或实际进入库并更新包,以便它使用来自单独包而不是React.PropTypes的新PropTypes。 This should fix your problem 这应该可以解决您的问题

Yes definitely, if you upgrade react: 15 or higher then you have to add import PropTypes from 'prop-types'; 是的,如果你升级反应:15或更高,那么你必须import PropTypes from 'prop-types';添加import PropTypes from 'prop-types';

But recently I faced the same issue in "react": "16.0.0-beta.5" after I changed 但是最近我在“反应”中遇到了同样的问题:“16.0.0-beta.5”在我改变之后

"dependencies": {
        "react": "16.0.0-alpha.12"
    },
    "devDependencies": {
        "react-test-renderer": "16.0.0-alpha.12"
    }

Then it found working fine. 然后它发现工作正常。 Hope it helps! 希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 undefined 不是对象(正在评估 'addProduct.price').. 我不知道为什么会出现此错误? - undefined is not an object(evaluating 'addedProduct.price').. I don't know why I am getting this error? ReactDataGrid:为什么我收到此错误类型错误:未定义不是 object(评估“rows.length”) - ReactDataGrid : why am I getting this error TypeError: undefined is not an object (evaluating 'rows.length') 未定义不是对象(评估&#39;_react.PropTypes.object&#39;) - undefined is not an object (evaluating '_react.PropTypes.object') React-Native-未定义不是对象(“评估_react3.default.PropTypes.shape”) - React-Native – undefined is not an object (“evaluating _react3.default.PropTypes.shape”) React-Native - undefined 不是一个对象(“评估 _react3.default.PropTypes.shape”) - React-Native - undefined is not an object (“evaluating _react3.default.PropTypes.shape”) PropTypes.shape的默认默认prop类型应该是什么? - What should be react default prop type for PropTypes.shape? TypeError: undefined is not an object(评估'_reactNative.Image.propTypes.resizeMode') - TypeError: undefined is not an object (evaluating '_reactNative.Image.propTypes.resizeMode') React Native,未定义不是 object(评估 '_reactNative.Image.propTypes.resizeMode') - React Native, undefined is not an object (evaluating ‘_reactNative.Image.propTypes.resizeMode’) 未定义不是对象(评估“React.PropTypes.Number”)错误 - Undefined is not an object (evaluating 'React.PropTypes.Number') error 错误 PropTypes React Native undefined is not an object(评估'_propTypes.default.nymber.isRequired') - Error PropTypes React Native undefined is not an object (evaluating '_propTypes.default.nymber.isRequired')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM