我在这段代码中遇到了一些问题,我正在按照react-native-redux教程学习。我不得不build.gradle
根据我的Android SDK版本更改一些编译器版本,请问有人指出我在哪里做错了吗?
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;
}
}
该connect
功能不是的默认导出react-redux
。您必须像这样导入它:
import {connect} from 'react-redux';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句