@@ -81,15 +81,6 @@ function PydanticFormContextProvider({
81
81
82
82
const formRef = useRef < string > ( formKey ) ;
83
83
84
- useEffect ( ( ) => {
85
- if ( formKey !== formRef . current ) {
86
- // When the formKey changes we need to reset the form input data
87
- setFormInputData ( [ ] ) ;
88
- setFormInputHistory ( new Map < string , object > ( ) ) ;
89
- formRef . current = formKey ;
90
- }
91
- } , [ formKey ] ) ;
92
-
93
84
useEffect ( ( ) => {
94
85
const getLocale = ( ) => {
95
86
switch ( locale ) {
@@ -208,13 +199,15 @@ function PydanticFormContextProvider({
208
199
values : initialData ,
209
200
} ) ;
210
201
211
- const resetFormData = useCallback (
212
- ( inputData ?: object ) => {
213
- // Resetting without inputData will reset to defaultValues
214
- rhf . reset ( inputData || undefined ) ;
215
- } ,
216
- [ rhf ] ,
217
- ) ;
202
+ useEffect ( ( ) => {
203
+ if ( formKey !== formRef . current ) {
204
+ // When the formKey changes we need to reset the form input data
205
+ setFormInputData ( [ ] ) ;
206
+ setFormInputHistory ( new Map < string , object > ( ) ) ;
207
+ rhf ?. reset ( { } ) ;
208
+ formRef . current = formKey ;
209
+ }
210
+ } , [ formKey , rhf ] ) ;
218
211
219
212
rhfRef . current = rhf ;
220
213
@@ -259,15 +252,8 @@ function PydanticFormContextProvider({
259
252
}
260
253
261
254
setFormInputHistory ( new Map < string , object > ( ) ) ;
262
- resetFormData ( ) ;
263
- } , [
264
- apiResponse ,
265
- isFullFilled ,
266
- onSuccess ,
267
- resetFormData ,
268
- rhf ,
269
- skipSuccessNotice ,
270
- ] ) ;
255
+ rhf . reset ( { } ) ;
256
+ } , [ apiResponse , isFullFilled , onSuccess , rhf , skipSuccessNotice ] ) ;
271
257
272
258
// a useeffect for whenever the error response updates
273
259
// sometimes we need to update the form,
@@ -280,7 +266,7 @@ function PydanticFormContextProvider({
280
266
281
267
// when we receive a new form from JSON, we fully reset the form
282
268
if ( apiResponse ?. form && rawSchema !== apiResponse . form ) {
283
- resetFormData ( ) ;
269
+ rhf . reset ( { } ) ;
284
270
setRawSchema ( apiResponse . form ) ;
285
271
if ( apiResponse . meta ) {
286
272
setHasNext ( ! ! apiResponse . meta . hasNext ) ;
@@ -304,10 +290,10 @@ function PydanticFormContextProvider({
304
290
const currentStepFromHistory = formInputHistory . get ( hash ) ;
305
291
306
292
if ( currentStepFromHistory ) {
307
- resetFormData ( currentStepFromHistory ) ;
293
+ rhf . reset ( currentStepFromHistory ) ;
308
294
}
309
295
} ) ;
310
- } , [ formInputData , formInputHistory , resetFormData , rhf ] ) ;
296
+ } , [ formInputData , formInputHistory , rhf ] ) ;
311
297
312
298
// this is to show an error whenever there is an unexpected error from the backend
313
299
// for instance a 500
@@ -348,11 +334,11 @@ function PydanticFormContextProvider({
348
334
const resetForm = useCallback (
349
335
( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
350
336
e . preventDefault ( ) ;
351
- resetFormData ( ) ;
352
337
setErrorDetails ( undefined ) ;
338
+ rhf . reset ( ) ;
353
339
rhf . trigger ( ) ;
354
340
} ,
355
- [ resetFormData , rhf ] ,
341
+ [ rhf ] ,
356
342
) ;
357
343
358
344
const resetErrorDetails = useCallback ( ( ) => {
0 commit comments