Skip to content

Commit

Permalink
feat(field.tsx): add suspenseFallback to createField
Browse files Browse the repository at this point in the history
  • Loading branch information
duongductrong committed Jun 23, 2024
1 parent 58f988f commit 0466ee4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface CreateFieldOptions {
message?: keyof JSX.IntrinsicElements
description?: keyof JSX.IntrinsicElements
}

suspenseFallback?: ReactNode
}

type InferComponentProps<T> = T extends React.ComponentType<infer P> ? P : never
Expand Down Expand Up @@ -81,11 +83,12 @@ export function createField<T extends Record<string, React.ComponentType<any>>>(
}) => {
const customComponents = options?.components
const customClassnames = options?.classNames
const customSuspenseFallback = options?.suspenseFallback

const InputComp = useMemo(() => components[component], [component])

return (
<Suspense fallback={suspenseFallback}>
<Suspense fallback={customSuspenseFallback || suspenseFallback}>
<FormField
name={name}
render={({ field, formState: { errors } }) => {
Expand Down

0 comments on commit 0466ee4

Please sign in to comment.