简体   繁体   English

反应本机错误

[英]React Native Error

I'm trying to use tcomb-form-native in my react-native (android) app but i get this error msg: undefined is not an object (evaluating '_react.PropTypes.string') react native 我正在尝试在我的react-native (android)应用程序中使用tcomb-form-native ,但出现此错误msg: undefined is not an object (evaluating '_react.PropTypes.string')反应本机

I used following commands for install tcomb-form-native : 我使用以下命令来安装tcomb-form-native:

npm install tcomb-form-native 
npm install tcomb --save 
npm install tcomb-json-schema

this is my code : 这是我的代码:

Sign in.js 登录.js

import React, { Component, PropTypes } from 'react';
import {
    StyleSheet,
    Image,
    KeyboardAvoidingView,
    Alert,
    TouchableHighlight,
} from 'react-native';
import t from 'tcomb-form-native';


const Form = t.form.Form;

const Login = t.struct({
    username: t.String,
    password: t.String
});

const options = {
    fields: {
        password: {
            type: 'password',
            placeholder: 'Password',
        },
        username: {
            placeholder: 'e.g: abc@gmail.com',
            error: 'Insert a valid email'
        }
    }
}

class SignIn extends Component {

    onPress() {
        const value = this.refs.form.getValue();
        if (value) {
            console.log(value);
        }
    };

    render() {
        return (
            <View style={styles.container}>
                <Form
                    ref="form"
                    type={Login}
                    options={options}
                />

                <Text style={{color: 'blue', marginBottom: 10}}
                      onPress={() => Linking.openURL('https://www.google.co.in')}>
                    Forgot Password?
                </Text>

                <TouchableHighlight style={styles.button} onPress={this.onPress} underlayColor='#99d9f4'>
                    <Text style={styles.buttonText}>Sign In</Text>
                    </TouchableHighlight>
            </View>
        );
    }
}

var styles = StyleSheet.create({
    container: {
        justifyContent: 'center',
        marginTop: 50,
        padding: 20,
        backgroundColor: '#ffffff',
    },
    title: {
        fontSize: 30,
        alignSelf: 'center',
        marginBottom: 30
    },
    buttonText: {
        fontSize: 18,
        color: 'white',
        alignSelf: 'center'
    },
    button: {
        height: 36,
        backgroundColor: '#48BBEC',
        borderColor: '#48BBEC',
        borderWidth: 1,
        borderRadius: 8,
        marginBottom: 10,
        alignSelf: 'stretch',
        justifyContent: 'center'
    }
});

export default SignIn;

Index.js Index.js

import React, { Component } from 'react';
import { Scene, Router } from 'react-native-router-flux';
import Page1  from './src/page1';
import Page2  from './src/page2';
import Login from './src/components/login/Login';
import SignUp from './src/components/login/SignUp';
import SignIn from './src/components/login/SignIn';
import GeoMap from './src/components/maps/GeoMap';

class App extends Component {
  render() {
    return (
      <Router>
          <Scene key="root">
          <Scene key="signIn"   component={SignIn} hideNavBar={true}  title="Sign In" initial="true"/>
          <Scene key="login"    component={Login} hideNavBar={true}  title="Login" />
          <Scene key="p1"       component={Page1}   title="Page1" />
          <Scene key="p2"       component={Page2}   title="Page2" />
          <Scene key="signIn"   component={Login}   title="Sign In" />
          <Scene key="signUp"   component={SignUp}  title="Sign Up" />
          <Scene key="geoMap"   component={GeoMap}  title="Maps" />
        </Scene>
      </Router>
    );
  }
}

export default App;

index.android.js index.android.js

import {
    AppRegistry
} from 'react-native';
import App from './app/index';

AppRegistry.registerComponent('GravitonApp', () => App);

在此处输入图片说明

Since React v15.5, React.PropTypes has moved into a different package. 从React v15.5开始,React.PropTypes已移至其他包中。 You should use the prop-types library instead. 您应该改为使用prop-types库。

import PropTypes from 'prop-types'

instead of 代替

import { PropTypes } from 'react'

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM