0
votes

For inputs with type text it's easy, with onChange() I update the state calling setState() and showing the state on the input through its value attribute. However, for checkboxes and even more for file, I'm totally lost.

Which would be the:

  1. handler
  2. property of the event object
  3. attribute ... for input>checkbox and input>file

Example of input>text

  1. onChange()
  2. event.target.value
  3. value
1

1 Answers

1
votes

For checkbox you can check using using the following :

handleChange(e) {
  console.log(e.target.checked);
}
<input 
  type="checkbox" 
  name="checkbox"
  onChange={ this.handleChange } 
/>

For files you can go as follows:

handleUploadFile(e) {
  let selectedFile = e.target.files;
  //if single file
  console.log(selectedFile[0]);
  //else loop around the files
  ...
}