-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enabled nested rendering of schema with SchemaRenderer component
- Loading branch information
1 parent
f6816c2
commit 4121026
Showing
4 changed files
with
64 additions
and
19 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
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
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,36 @@ | ||
import { SchemaType } from "@/interfaces/schema"; | ||
import InputField from "../fields/InputField"; | ||
import { FieldErrors, UseFormRegister } from "react-hook-form"; | ||
import { TFormValues } from "@/App"; | ||
|
||
type SchemaRendererProps = { | ||
schema: SchemaType; | ||
errors: FieldErrors<Record<string, string>>; | ||
register: UseFormRegister<TFormValues>; | ||
}; | ||
|
||
const SchemaRenderer = (props: SchemaRendererProps) => { | ||
const { schema, errors, register } = props; | ||
|
||
return schema.fields.map((field) => { | ||
if (field.type === "field") { | ||
return ( | ||
<InputField | ||
key={`key-${field.accessorKey}`} | ||
register={register} | ||
labelText={field.fieldName} | ||
htmlFor={field.accessorKey} | ||
type={field.dataType} | ||
validation={field.validation} | ||
error={errors[field.accessorKey]} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<SchemaRenderer schema={field} errors={errors} register={register} /> | ||
); | ||
}); | ||
}; | ||
|
||
export default SchemaRenderer; |
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