Flat arrays #7770
-
Hello, was wondering if it is going to be possible to have flat arrays, to do something like this: I keep getting warnings like these: Best Regards! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
RHF doesn't support flat arrays ATM.
|
Beta Was this translation helpful? Give feedback.
-
None of the solutions worked for me, here's what worked: export function useFlatArray<TFieldValues extends FieldValues>({
name,
control
}: {
name: FieldArrayPath<TFieldValues>;
control: Control<TFieldValues>;
}) {
const fieldArray = useFieldArray({ control, name });
return {
...fieldArray,
append(value: string) {
fieldArray.append(
// @ts-ignore
new String(value)
);
}
};
} And then, if you're using |
Beta Was this translation helpful? Give feedback.
RHF doesn't support flat arrays ATM.
Ref: RHF docs on useFieldArray: