2016-11-01 2 views
0

Ich bin derzeit ein grundlegendes Tutorial auf React Native Authentifizierung folgen. Als ich das Projekt zu starten, gibt es folgende Fehlermeldung:Der Zugriff auf ReactNative.Component Fehler versucht

enter image description here

ich den Fehler verstehen, kann aber nicht sehen, was ich falsch mache. Insbesondere habe ich meine Ansichten auskommentiert, bis der Fehler verschwunden und das Projekt kompiliert wurde. Hier ist der Täter. Warum sollte ein solcher Fehler auftreten?

import React, { Component } from 'react'; 

import { 
    ScrollView, 
    StyleSheet, 
    TouchableHighlight, 
    Text 
} from 'react-native'; 

const t = require('tcomb-form-native'); 

const Form = t.form.Form 

const newUser = t.struct({ 
    email: t.String, 
    password: t.String 
}) 

const options = { 
    fields: { 
    email: { 
     autoCapitalize: 'none', 
     autoCorrect: false 
    }, 
    password: { 
     autoCapitalize: 'none', 
     password: true, 
     autoCorrect: false 
    } 
    } 
} 

class RegisterView extends Component { 

    constructor(props) { 
    super(props) 
    this.state = { 
     value: { 
     email: '', 
     password: '' 
     } 
    } 
    } 

    componentWillUnmount() { 
    this.setState = { 
     value: { 
     email: '', 
     password: null 
     } 
    } 
    } 

    _onChange = (value) => { 
    this.setState({ 
     value 
    }) 
    } 

    _handleAdd =() => { 
    const value = this.refs.form.getValue(); 
    // If the form is valid... 
    if (value) { 
     const data = { 
     email: value.email, 
     password: value.password, 
     } 
     // Serialize and post the data 
     const json = JSON.stringify(data); 
     fetch('http://localhost:3000/users/register', { 
     method: 'POST', 
     headers: { 
      'Content-Type': 'application/json', 
      Accept: 'application/json' 
     }, 
     body: json 
     }) 
     .then((response) => response.json()) 
     .then(() => { 
     alert('Success! You may now log in.'); 
     // Redirect to home screen 
     this.props.navigator.pop(); 
     }) 
     .catch((error) => { 
     alert('There was an error creating your account.'); 
     }) 
     .done() 
    } else { 
     // Form validation error 
     alert('Please fix the errors listed and try again.') 
    } 
    } 

    render() { 
    return (
     <ScrollView style={styles.container}> 
     <Form 
      ref='form' 
      type={newUser} 
      options={options} 
      value={this.state.value} 
      onChange={this._onChange} 
     /> 
     <TouchableHighlight onPress={this._handleAdd}> 
      <Text style={[styles.button, styles.greenButton]}>Create account</Text> 
     </TouchableHighlight> 
     </ScrollView> 
    ) 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
    padding: 20, 
    flex: 1, 
    flexDirection: 'column' 
    }, 
    button: { 
    borderRadius: 4, 
    padding: 20, 
    textAlign: 'center', 
    marginBottom: 20, 
    color: '#fff' 
    }, 
    greenButton: { 
    backgroundColor: '#4CD964' 
    }, 
    centering: { 
    alignItems: 'center', 
    justifyContent: 'center' 
    } 
}) 

module.exports = RegisterView 
+0

Welche Version von tcomb-form-native verwenden Sie? – Jickson

+0

vielleicht tcomb-from-native nicht aktualisieren, wie @Jickson sagte –

+0

"tcomb-form-native": "^ 0.4.4" – MadPhysicist

Antwort

0

Laut Dokumentation von tcomb-form-native,

tcomb-form-native ^0.5: react-native >= 0.25.0 tcomb-form-native ^0.4: react-native >= 0.20.0 tcomb-form-native ^0.3: react-native < 0.13.0

Mein react-native --version war

react-native-cli: 1.0.0 react-native: 0.36.0

Daher läuft npm install [email protected] das Problem für mich gelöst.

Verwandte Themen