@@ -170,6 +170,7 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
170
170
const [ validateState , setValidateState ] = useState ( { } ) ;
171
171
const changeRef = useRef ( false )
172
172
const touchRef = useRef ( false ) ;
173
+ const [ localInputValue , setLocalInputValue ] = useState < string > ( '' ) ;
173
174
174
175
const propsRef = useRef < RecordConstructorToView < typeof textInputChildren > > ( props ) ;
175
176
propsRef . current = props ;
@@ -181,20 +182,26 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
181
182
props . value . onChange ( defaultValue )
182
183
} , [ defaultValue ] ) ;
183
184
185
+ useEffect ( ( ) => {
186
+ if ( inputValue !== localInputValue ) {
187
+ setLocalInputValue ( inputValue ) ;
188
+ }
189
+ } , [ inputValue ] ) ;
190
+
184
191
useEffect ( ( ) => {
185
192
if ( ! changeRef . current ) return ;
186
193
187
194
setValidateState (
188
195
textInputValidate ( {
189
196
...propsRef . current ,
190
197
value : {
191
- value : inputValue ,
198
+ value : localInputValue ,
192
199
} ,
193
200
} )
194
201
) ;
195
202
propsRef . current . onEvent ( "change" ) ;
196
203
changeRef . current = false ;
197
- } , [ inputValue ] ) ;
204
+ } , [ localInputValue ] ) ;
198
205
199
206
useEffect ( ( ) => {
200
207
if ( ! touchRef . current ) return ;
@@ -203,7 +210,7 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
203
210
textInputValidate ( {
204
211
...propsRef . current ,
205
212
value : {
206
- value : props . value . value ,
213
+ value : localInputValue ,
207
214
} ,
208
215
} )
209
216
) ;
@@ -212,19 +219,26 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
212
219
const debouncedOnChangeRef = useRef (
213
220
debounce ( ( value : string ) => {
214
221
props . value . onChange ( value ) ;
215
- changeRef . current = true ;
216
- touchRef . current = true ;
217
222
} , 1000 )
218
223
) ;
219
224
220
225
const handleChange = ( e : ChangeEvent < HTMLInputElement > ) => {
221
226
const value = e . target . value ;
227
+ setLocalInputValue ( value ) ;
228
+
229
+ changeRef . current = true ;
230
+ touchRef . current = true ;
222
231
debouncedOnChangeRef . current ?.( value ) ;
223
232
} ;
224
233
225
234
return [
226
235
{
227
- ...textInputProps ( props ) ,
236
+ ...textInputProps ( {
237
+ ...props ,
238
+ value : {
239
+ value : localInputValue ,
240
+ } as any ,
241
+ } ) ,
228
242
onChange : handleChange ,
229
243
} ,
230
244
validateState ,
0 commit comments