File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,6 @@ import 'react-input-verification-code/dist/index.css';
6
6
import './index.css' ;
7
7
8
8
ReactDOM . render (
9
- < ReactInputVerificationCode /> ,
9
+ < ReactInputVerificationCode onChange = { console . log } /> ,
10
10
document . getElementById ( 'root' )
11
11
) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ const KEY_CODE = {
8
8
DELETE : 46 ,
9
9
} ;
10
10
11
- export default ( { length = 4 , placeholder = '·' } ) => {
11
+ type Props = {
12
+ length ?: number ;
13
+ onChange : ( data : string ) => any ;
14
+ placeholder ?: string ;
15
+ } ;
16
+
17
+ export default ( { length = 4 , onChange, placeholder = '·' } : Props ) => {
12
18
const [ activeIndex , setActiveIndex ] = React . useState < number > ( - 1 ) ;
13
19
const [ value , setValue ] = React . useState < string [ ] > (
14
20
new Array ( length ) . fill ( placeholder )
@@ -93,6 +99,10 @@ export default ({ length = 4, placeholder = '·' }) => {
93
99
blurItem ( activeIndex ) ;
94
100
} ;
95
101
102
+ React . useEffect ( ( ) => {
103
+ onChange ( value . join ( '' ) ) ;
104
+ } , [ value ] ) ;
105
+
96
106
return (
97
107
< div
98
108
className = 'ReactInputVerificationCode__container'
You can’t perform that action at this time.
0 commit comments