@@ -81,15 +81,6 @@ function PydanticFormContextProvider({
8181
8282 const formRef = useRef < string > ( formKey ) ;
8383
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-
9384 useEffect ( ( ) => {
9485 const getLocale = ( ) => {
9586 switch ( locale ) {
@@ -208,13 +199,15 @@ function PydanticFormContextProvider({
208199 values : initialData ,
209200 } ) ;
210201
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 ] ) ;
218211
219212 rhfRef . current = rhf ;
220213
@@ -259,15 +252,8 @@ function PydanticFormContextProvider({
259252 }
260253
261254 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 ] ) ;
271257
272258 // a useeffect for whenever the error response updates
273259 // sometimes we need to update the form,
@@ -280,7 +266,7 @@ function PydanticFormContextProvider({
280266
281267 // when we receive a new form from JSON, we fully reset the form
282268 if ( apiResponse ?. form && rawSchema !== apiResponse . form ) {
283- resetFormData ( ) ;
269+ rhf . reset ( { } ) ;
284270 setRawSchema ( apiResponse . form ) ;
285271 if ( apiResponse . meta ) {
286272 setHasNext ( ! ! apiResponse . meta . hasNext ) ;
@@ -304,10 +290,10 @@ function PydanticFormContextProvider({
304290 const currentStepFromHistory = formInputHistory . get ( hash ) ;
305291
306292 if ( currentStepFromHistory ) {
307- resetFormData ( currentStepFromHistory ) ;
293+ rhf . reset ( currentStepFromHistory ) ;
308294 }
309295 } ) ;
310- } , [ formInputData , formInputHistory , resetFormData , rhf ] ) ;
296+ } , [ formInputData , formInputHistory , rhf ] ) ;
311297
312298 // this is to show an error whenever there is an unexpected error from the backend
313299 // for instance a 500
@@ -348,11 +334,11 @@ function PydanticFormContextProvider({
348334 const resetForm = useCallback (
349335 ( e : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
350336 e . preventDefault ( ) ;
351- resetFormData ( ) ;
352337 setErrorDetails ( undefined ) ;
338+ rhf . reset ( ) ;
353339 rhf . trigger ( ) ;
354340 } ,
355- [ resetFormData , rhf ] ,
341+ [ rhf ] ,
356342 ) ;
357343
358344 const resetErrorDetails = useCallback ( ( ) => {
0 commit comments