Skip to content

Commit db91425

Browse files
committed
useSyncTranslations: add types and jsdocs
1 parent ad6e8ff commit db91425

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

client/common/useSyncFormTranslations.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, MutableRefObject } from 'react';
22

3-
// Usage: useSyncFormTranslations(formRef, language)
4-
// This hook ensures that form values are preserved when the language changes.
5-
// Pass a ref to the form instance and the current language as arguments.
6-
const useSyncFormTranslations = (formRef, language) => {
3+
export interface FormLike {
4+
getState(): { values: Record<string, unknown> };
5+
reset(): void;
6+
change(field: string, value: unknown): void;
7+
}
8+
9+
/**
10+
* This hook ensures that form values are preserved when the language changes.
11+
* @param formRef
12+
* @param language
13+
*/
14+
const useSyncFormTranslations = (
15+
formRef: MutableRefObject<FormLike>,
16+
language: string
17+
) => {
718
useEffect(() => {
819
const form = formRef.current;
920
if (!form) return;

0 commit comments

Comments
 (0)