How can i pass the data from redux form, So that i can access that data in App.js? here is the code i have written using redux-form.after i click on submit the data should be passed from form.js to app.js. and the data should be displayed on page.
here is form.js-
const Form=({fields:{name,address}})=>(
<form>
<center>
<div>
<label>First Name</label>
<Field type="text" component="input" placeholder="Name" name="name"/>
</div>
<div>
<label>Address</label>
<Field type="text" component="input" placeholder="Phone" name="phone" />
</div>
<button type="submit">Submit</button>
</center>
</form>
)
export default reduxForm({
form: 'form',
fields: ['name', 'address']
})(Form);
how can i pass this inputed data to app.js?
To get them, you will need to connect() directly to the form values in the Redux store. To facilitate this common use case, redux-form provides a convenient selector via the formValueSelector API.
It's simple to get access to the store inside a React component – no need to pass the store as a prop or import it, just use the connect function from React Redux, and supply a mapStateToProps function that pulls out the data you need. Then, inside the component, you can pass that data to a function that needs it.
1 Answer. Show activity on this post. Generally, it's expected that something with 'redux' in title won't work without Redux, otherwise this would be a terrible name for a package. If a package is advertised to be useable with Redux but isn't limited to it, its name doesn't contain 'redux'.
The FieldArray component is how you render an array of fields. It works a lot like Field . With Field , you give a name , referring to the location of the field in the Redux state, and a component to render the field, which is given the props to connect the field to the Redux state.
What you need to do is use getFormValues
to get the redux field
values
So in App.js you can have
import {getFormValues} from 'redux-form';
..
const App = (props) => {
var {name, phone} = props.formStates
console.log(name, phone);
}
function mapStateToProps(state) {
return {
formStates: getFormValues('form')(state) // here 'form' is the name you have given your redux form
}
}
export default connect(mapStateToProps)(App)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With