Answer the question
In order to leave comments, you need to log in
How to get input values when handling onSubmit in React-redux?
Question on handling the onSubmit event in a redux app:
I'm trying to use @material-ui/core
. In the form, the event onSubmit
is called Action
, but I don’t understand how to transfer it to the Action
value of the form fields. Those. I can hang an Action on each field on an event onChange
and write to store
the field value, but then every character will be written to the store, which is useless. When called Action
, it is passed SyntheticEvent
which has a target property, but there is a list of home nodes, how to get the values of the imputs from them?
form itself:
import {
Button,
TextField,
Card,
CircularProgress,
} from '@material-ui/core'
....
<form className="login-form" onSubmit={handleLogin}>
<TextField
id="login-form__text-input"
label="Name"
className="login-form__text-input"
// value={username}
// onChange={handleChange}
margin="normal"
variant="outlined"
required
/>
.....
const mapDispatchToProps = dispatch => {
return {
handleLogin: (e) =>
dispatch(handleLogin(e)),
handleChange: () => dispatch(handleChange())
}
}
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(LoginFormContainer)
)
Answer the question
In order to leave comments, you need to log in
Loop through the nodes and collect all the data you need.
OnSumbit works on the form, respectively, in children, the form has all the inputs with values.
In general, you can use ready-made libraries:
https://github.com/jaredpalmer/formik
https://github.com/final-form/react-final-form
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question