react file input clear code example

Example 1: clear input file html react

e.target.value = null;

Example 2: react clear form input field

// React.js
// Set button type to "reset"
<Form>
	<Input placeholder="Input"/>
    // ...
	// Set type="reset"
	<Button type="reset">Submit</Button>
</Form>

Example 3: react reset file input

functionThatResetsTheFileInput() {
  let randomString = Math.random().toString(36);

  this.setState({
    theInputKey: randomString
  });
}

render() {
  return(
    <div>
      <input type="file"
             key={this.state.theInputKey || '' } />
      <button onClick={this.functionThatResetsTheFileInput()} />
    </div>
  )
}

Tags:

Html Example