0
我在ReactJS中使用一個Redux Store創建了一個auth系統。在執行Signin Class時,它在控制檯中顯示未定義,未定義。我在下面包含了signin.js文件和reducer文件。登錄組件在console.log中未定義
SRC /組件/ AUTH/signin.js
import React, { Component } from 'react';
import { reduxForm } from 'redux-form';/*
import * as actions from '../../actions';*/
class Signin extends Component {
handleFormSubmit({ email, password }){
/*actions.signinUser({ email, password });*/
console.log(email,password);
}
render() {
// code
const { handleSubmit, fields: { email, password }} = this.props;
return (
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
<fieldset className="form-group">
<label>Email:</label>
<input {...email} className="form-control" />
</fieldset>
<fieldset className="form-group">
<label>Password:</label>
<input {...password} className="form-control" />
</fieldset>
<button action="submit" className="btn btn-primary">Sign In</button>
</form>
);
}
// methods
}
export default reduxForm({
form: 'signin',
fields: ['email', 'password']
})(Signin);
的src /減速器/ index.js
import { combineReducers } from 'redux';
import { reducer as form } from 'redux-form';
const rootReducer = combineReducers({
form
});
export default rootReducer;
控制檯
undefined, undefined
'handleFormSubmit'傳遞給一個[**事件對象**](https://facebook.github.io/react/docs/events.html)。事件對象不具有「email」和「password」屬性。所以你的輸出是預期的。如果您想獲取輸入字段的值,請使用[受控組件](https://facebook.github.io/react/docs/forms.html)。 –