Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
how can i get value from event in react?

this is my function that i use in my login component so that when i change my email it changes it value

   handleChange =e=>{
    //clone
    let username = {...this.state.username};
    //edit
    username = e.currrentTarget.value;
    //change state
    this.setState({username});
}

and i call this function in the following lines

          <form onSubmit ={this.handleSubmit}>
        <div className="mb-3">
            <label htmlFor="exampleInputEmail1" class="form-label">Email address</label>
            <input
             value= {this.state.username}
             onChange = {this.handleChange}
             type="email" 
             className="form-control" 
             id="exampleInputEmail1" 
             aria-describedby="emailHelp"/>
            <div id="emailHelp" className="form-text">We'll never share your email with anyone else.</div>
        </div>

so i get this errors

Warning: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.
at input
at div
at form
at Login (http://localhost:3000/static/js/main.chunk.js:831:5)
at Routes (http://localhost:3000/static/js/vendors~main.chunk.js:33026:5)
at main
at App (http://localhost:3000/static/js/main.chunk.js:238:5)
at Router (http://localhost:3000/static/js/vendors~main.chunk.js:32959:15)
at BrowserRouter (http://localhost:3000/static/js/vendors~main.chunk.js:32474:5)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Okay, so that's not an error. You need to use a connected component in this case.

<input
  value={this.state.username}
  onChange={this.handleChange}
  type="email"
  className="form-control"
  id="exampleInputEmail1"
  aria-describedby="emailHelp"
/>

For some reason, the this.handleChange seems null or undefined.

Show us your full code for debugging. Alternatively, try using:

<input
  value={this.state.username}
  onChange={handleChange}
  type="email"
  className="form-control"
  id="exampleInputEmail1"
  aria-describedby="emailHelp"
/>

Also, remember, there could be some cached error messages, so refresh once.

This is not an error, it's just a warning.

You can either use e.target.value or whatever you're using now.

handleChange = e => {
  // also you're not using it right.
  // because username is just a string value not an object.
  // let username = { ...this.state.username };
  // it should be:
  let username = this.state.username;
  //edit
  username = e.currrentTarget.value;
  //change state
  this.setState({ username });
};

Kindly see the above code block for comments on where you went wrong.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda