2016-12-03 23 views
0

我在這個代碼中我有一些問題,我正在遵循教程react-native-redux.I不得不改變一些build.gradle編譯器版本,以適應根據我的Android SDK Version.Please任何人都可以指出我犯了什麼錯誤?undifined是不是一個功能,反應redux

enter image description here

import React, { Component } from 'react'; 
import { View, Text } from 'react-native'; 
import firebase from 'firebase'; 
import connect from 'react-redux'; 
import {emailChanged} from '../actions'; 
import { Spinner, Header, Button, Card, CardSection, Input } from './common'; 


class LoginForm extends Component { 

// constructor() { 
//  super(); 
//  this.onEmailChange = this.onEmailChange.bind(this); 
// } 

onEmailChange(text) { 
    //step 1 : trigger the action with new text 
    this.props.emailChanged(text); 
} 

render() { 
    return (
     <Card> 
      <CardSection> 
       <Header text="Please Login" /> 
      </CardSection> 
      <CardSection> 
       <Input placeholder="[email protected]" 
        labelText="e Mail" 
        onChangeText={this.onEmailChange.bind(this)} 
        //set the value with previous text 
        value={this.props.email} 
        /> 

      </CardSection> 
      <CardSection> 

       <Input encrypt={true} labelText="Password" /> 
      </CardSection> 
      <CardSection> 
       <Button>Login Here</Button> 
      </CardSection> 

     </Card> 
    ); 
    } 

}; 

// get the state(session) and assign to props 
const mapStateToProps = (state) => { 
    return { 
    //return empty objetc with assigned session.reducerName.propertyName as props 
    email : state.auth.email 
    }; 
}; 


export default connect(mapStateToProps,{emailChanged})(LoginForm); 

操作

import Types from './types'; 

export const emailChanged = (text) => { 
    return { 
    type : Types.EMAIL_CHANGED , 
    payload : text 
    }; 
}; 

減速

import Types from '../actions/types'; 

const INITIAL_STATE = { email: '' }; 

export default (state = INITIAL_STATE, action) => { 
switch (action.type) { 

    case Types.EMAIL_CHANGED: 
     //need a brand new object when returning - Theory 
     // return an empty object with all properties of state with email updated with action.payload 
     return { ...state, email: action.payload }; 

    default: 
     return state; 
} 

} 
+0

刪除註釋行中的登錄表單 –

回答

1

connect功能不是react-redux默認的導出。你必須導入它是這樣的:

import {connect} from 'react-redux'; 
+0

的構造喔是的,我怎麼能錯過,that.you救了我從trouble.Thank你 – Azela

+0

的天作爲一個經驗法則,如果你有「undefined不是...」的錯誤,去看看你的進口「:D。很高興它幫助! – martinarroyo

相關問題