BearStudio / start-ui-web

πŸš€ Start UI [web] is an opinionated UI starter with 🟦 TypeScript, βš›οΈ React, ⚫️ NextJS, ⚑️ Chakra UI, 🟦 tRPC, β–² Prisma, πŸ–οΈ TanStack Query, πŸ“• Storybook, 🎭 Playwright,πŸ“‹ React Hook Form,β—½From the 🐻 BearStudio Team
https://demo.start-ui.com
MIT License
1.36k stars 128 forks source link

Cleaner React-Hook-Form implementation #475

Closed ntatoud closed 1 month ago

ntatoud commented 3 months ago

In the Form and Fields components declaration, wouldn't it be better to :

Remove the control props from FormFields in Forms.

Because the fields are used in a FormProvider context, there is no need to pass the control prop to the FormField component Exemple :

  <Form {...form} onSubmit={onSubmit}>
      <Stack spacing={4}>
        <FormField
          size="lg"
          type="text"
          name="email"
          control={form.control} ❌ Not needed
          label="Email"
        />
        <FormField
          size="lg"
          type="password"
          name="password"
          control={form.control} ❌ Not needed
          label="Password"
        />

        <HStack justify="end">
          <Button
            type="submit"
            variant="@primary"
            isLoading={login.isPending}
            justifySelf="end"
          >
            Login
          </Button>
        </HStack>
      </Stack>
    </Form>
ivan-dalmet commented 1 month ago

The control props is needed for typesafety ;)