내 양식의 상태를 LoginForm 구성 요소의 소품에 매핑하려고 시도 중 상태가 undefined
으로 표시됩니다. 난 그냥 로그 소품 단지 상태를 매핑하고 콘솔 경우상태를 반응에서 소품으로 매핑 할 때의 상태가 정의되지 않았습니다.
import React, { PropTypes } from 'react';
import { Field, Form } from 'redux-form/immutable';
import { getClassName } from '../../utils/forms';
import { Link } from 'react-router';
// import { checkButtonDisabled } from '../../utils/forms';
const renderInput = ({ input, label, type, meta: { touched, error } }) => {
return (
<div className={ getClassName(touched, error) }>
<label className="form-control-label">
{ label }
{touched && error &&
<span className="error">{ error }</span>}
</label>
<input
{ ...input }
className="form-control form-control-success"
type={ type }
/>
</div>
);
};
export default class LoginForm extends React.Component {
static propTypes = {
handleSubmit: PropTypes.func.isRequired,
loginFunction: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired,
};
render() {
const {
handleSubmit,
loginFunction,
submitting } = this.props;
return (
<Form id="loginForm" onSubmit={ handleSubmit(loginFunction.bind(this)) }>
<fieldset>
<Field
name="email"
component={renderInput}
type="text"
placeholder="[email protected]"
label="Email address"
/>
<Field
name="password"
component={renderInput}
type="password"
placeholder="your password"
label="Password"
/>
</fieldset>
<button
type="submit"
className="btn btn-primary"
disabled={ submitting }
>
Log In
</button>
<Link to="/forgot-password">Forgot Password?</Link>
</Form>
);
}
}
, 그것은 또한 다시 undefined
로 제공 : 여기
import React, { PropTypes } from 'react';
import { reduxForm, getFormValues } from 'redux-form/immutable';
import { connect } from 'react-redux';
import { logUserIn } from '../../actions/authentication';
import { VALID_EMAIL_REGEX } from '../../config/app_config';
import LoginForm from './LoginForm';
const FORM_ID = 'loginForm';
export class LoginFormContainer extends React.Component {
static propTypes = {
handleSubmit: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired,
loginAction: PropTypes.func.isRequired,
values: PropTypes.object.isRequired,
};
performLogin = (params) => {
const { loginAction } = this.props;
const credentials = {
email: params.email,
password: params.password,
};
loginAction(credentials, '/home');
}
render() {
const { handleSubmit, submitting, values, ...others } = this.props;
console.log(values); // <--- undefined
return (
<LoginForm
handleSubmit={ handleSubmit }
loginFunction={ this.performLogin }
submitting={ submitting }
{...others}
/>
);
}
}
// there is a validate method here
LoginFormContainer = reduxForm({
form: FORM_ID, // <--- loginForm
validate,
})(LoginFormContainer);
const mapStateToProps = (state) => {
const values = getFormValues(FORM_ID)(state);
return {
values,
};
};
export default connect(mapStateToProps, {
loginAction: logUserIn,
})(LoginFormContainer);
는 LoginForm 구성 요소입니다.
내 제출 단추에서 조건을 설정하기 위해 값을 가져 오려고하지만 상태가 정의되지 않았으므로 양식 값을 얻기 위해 redux 양식 메서드를 실행하기 위해 양식 상태에 액세스 할 수 없습니다.
사람이 문제가 될 수있는 것을 발견 : 여기
은 국가의 사진을입니까?
'form'에'loginForm'이 있습니까? – Andrew
콘솔에 표시되는 상태를 보여주는 그림을 첨부했습니다. –
loginAction 전에 loginForm이 없거나 다른 작업 채우기 상태가있는 것 같습니다. 'const values = form.loginForm && form.loginForm.values '를 사용하여 확인하십시오. form.loginForm.values : null; ' – Andrew