0
所以我想從我的減速器訪問某些數據,所以我可以在我的validate.js使用它爲我的終極版,表單驗證如何訪問減速器在validate.js的終極版形式
const validate = (values, props) => {
const errors = {};
state.get('deposits').depositMethod // this is what I want to achieve
return errors;
};
class VisaDeposit extends React.Component {
render() {
const {
/* eslint-disable react/prop-types */
handleSubmit,
pristine,
reset,
submitting,
selectedCard,
} = this.props;
return (
<form onSubmit={handleSubmit}>
<div className={s.newField}>
<div>
<Field
id="numberOnCard"
label="Card number"
name="numberOnCard"
component={renderField}
type="text"
placeholder="Card number"
/>
</div>
</div>
<button
type="submit"
disabled={pristine || submitting}
className={s.submit}
>Submit
</button>
</form>
);
}
}
const selector = formValueSelector('accountDeposits');
const Form = reduxForm({
form: 'accountDeposits',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
validate,
})(VisaDeposit);
const StyledForm = withStyles(s)(Form);
function mapStateToProps(state) {
return {
selectedCard: selector(state, 'selectedCard'),
};
}
function mapDispatchToProps(dispatch) {
return {
loadRegisteredCards: bindActionCreators(loadRegisteredCards, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(StyledForm);
哪有我訪問狀態,所以我可以從我的減速器獲取數據?我試圖研究文檔和其他一切,但我似乎無法找到訪問狀態的方法。
我試過使用this.state
,但它返回一個未定義的值。
'的console.log(this.state.deposits.depositMethode);'這是什麼說? – Nocebo
你應該使用this.state沒有狀態 –
我試過記錄this.state,但它沒有定義atm –