File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -27,21 +27,22 @@ class Demo extends Component {
27
27
} ;
28
28
29
29
handleChange = e => {
30
- let currVal = e . target . value ;
30
+ this . setState ( { [ e . target . name ] : e . target . value } ) ;
31
+ } ;
31
32
32
- if ( e . target . name === 'numInputs' ) {
33
- const { minLength, maxLength } = this . state ;
33
+ handleNumInputsChange = e => {
34
+ let numInputs = e . target . value ;
35
+ const { minLength, maxLength } = this . state ;
34
36
35
- if ( currVal < minLength || currVal > maxLength ) {
36
- currVal = 4 ;
37
+ if ( numInputs < minLength || numInputs > maxLength ) {
38
+ numInputs = 4 ;
37
39
38
- console . error (
39
- `Please enter a value between ${ minLength } and ${ maxLength } `
40
- ) ;
41
- }
40
+ console . error (
41
+ `Please enter a value between ${ minLength } and ${ maxLength } `
42
+ ) ;
42
43
}
43
44
44
- this . setState ( { [ e . target . name ] : currVal } ) ;
45
+ this . setState ( { [ e . target . name ] : parseInt ( numInputs , 10 ) } ) ;
45
46
} ;
46
47
47
48
clearOtp = ( ) => {
@@ -91,7 +92,7 @@ class Demo extends Component {
91
92
name = "numInputs"
92
93
type = "number"
93
94
value = { numInputs }
94
- onChange = { this . handleChange }
95
+ onChange = { this . handleNumInputsChange }
95
96
min = { minLength }
96
97
max = { maxLength }
97
98
/>
You can’t perform that action at this time.
0 commit comments