R
R
RokeAlvo2019-06-16 09:58:32
React
RokeAlvo, 2019-06-16 09:58:32

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 onSubmitis called Action, but I don’t understand how to transfer it to the Actionvalue of the form fields. Those. I can hang an Action on each field on an event onChangeand write to storethe 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

1 answer(s)
S
Sergey Epifanov, 2019-06-16
@RokeAlvo

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 question

Ask a Question

731 491 924 answers to any question