MemoryLeak MemoryLeak - 1 month ago 12
Javascript Question

how to set default value to numeric input field in reactjs?

I am working on a sample reactjs form, which has a input number field as shown below:

<input type="number" name="quantity"
min="1"
step="1"
value={this.state.userCount}
onChange={this.handleUserCountChange}
/>


How to set the default value to 5 for the numeric field?

Answer

You would need to set the initial state of userCount to 5 check the docs : https://facebook.github.io/react/tutorial/tutorial.html#an-interactive-component