Witam, od razu powiem że jestem newbie w react i redux zatem stąd moje pytanie.
Mam utworzone dwa pliki ItemNew i ItemForm w item form używam Redux Forma i teraz chciałbym odczyta dane z formularza przez state w pliku ItemNew.
Dodatkowo pytanie , jak działa handleSubmit z Redux Forma czy on automatycznie wywołuje action creator i wstawia dane do state w Redux Store ?
import React, { Component } from "react";
import ItemForm from "./ItemForm";
import { connect } from "react-redux";
class ItemNew extends Component {
render(){
return(
<div>
<ItemForm />
</div>
);
}
}
function mapStateToProps(state){
return { formValues: state.form.itemForm.values }
}
export default connect(mapStateToProps)(ItemNew);
import React, { Component } from "react";
import {reduxForm, Field } from "redux-form";
import ItemField from "./ItemField";
class ItemForm extends Component {
render(){
const {handleSubmit} = this.props;
return(
<div>
<div className="box" id="">
<form className="item" onSubmit={handleSubmit}>
<Field type="text" name="taskName" component={ItemField} placeholder="Add Item"/>
<button type="submit">+</button>
</form>
</div>
</div>
);
}
}
function validate(values){
const errors = {};
if (!values.taskName) {
errors.taskName ="You must provide a task name";
}
return errors;
}
export default reduxForm({
validate,
form: "itemForm"
})(ItemForm);