@@ -111,12 +111,18 @@ function PydanticFormContextProvider({
111111 } ) ;
112112 } ;
113113
114- const addFormInputData = ( formInput : object ) => {
115- setFormInputData ( ( currentInputs ) => {
116- updateHistory ( formInput , currentInputs ) ;
117- return [ ...currentInputs , formInput ] ;
118- } ) ;
119- } ;
114+ const addFormInputData = useCallback (
115+ ( formInput : object , replaceInsteadOfAdd = false ) => {
116+ setFormInputData ( ( currentInputs ) => {
117+ const data = replaceInsteadOfAdd
118+ ? currentInputs . slice ( 0 , - 1 )
119+ : currentInputs ;
120+ updateHistory ( formInput , data ) ;
121+ return [ ...data , formInput ] ;
122+ } ) ;
123+ } ,
124+ [ ] ,
125+ ) ;
120126
121127 const [ errorDetails , setErrorDetails ] =
122128 useState < PydanticFormValidationErrorDetails > ( ) ;
@@ -289,10 +295,10 @@ function PydanticFormContextProvider({
289295
290296 const submitFormFn = useCallback ( ( ) => {
291297 setIsSending ( true ) ;
292- addFormInputData ( rhf ?. getValues ( ) ) ;
298+ addFormInputData ( rhf ?. getValues ( ) , ! ! errorDetails ) ;
293299
294300 window . scrollTo ( 0 , 0 ) ;
295- } , [ rhf ] ) ;
301+ } , [ rhf , errorDetails , addFormInputData ] ) ;
296302
297303 const onClientSideError = useCallback (
298304 ( data ?: FieldValues ) => {
0 commit comments