-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-2.15.3' into release
- Loading branch information
Showing
10 changed files
with
511 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useEffect } from 'react'; | ||
|
||
// Usage: useSyncFormTranslations(formRef, language) | ||
// This hook ensures that form values are preserved when the language changes. | ||
// Pass a ref to the form instance and the current language as arguments. | ||
const useSyncFormTranslations = (formRef, language) => { | ||
useEffect(() => { | ||
const form = formRef.current; | ||
if (!form) return; | ||
|
||
const { values } = form.getState(); | ||
form.reset(); | ||
|
||
Object.keys(values).forEach((field) => { | ||
if (values[field]) { | ||
form.change(field, values[field]); | ||
} | ||
}); | ||
}, [language]); | ||
}; | ||
|
||
export default useSyncFormTranslations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.