Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will not work if we pass value externally or like as sample given for hook form #93

Open
imdkbj opened this issue Aug 26, 2024 · 0 comments

Comments

@imdkbj
Copy link

imdkbj commented Aug 26, 2024

Error and that is expected

Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

import { useFormContext } from 'react-hook-form'
import {
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage
} from '@/components/ui/form'
import { DatetimePicker } from './date-time-input'

export default function HookDateTime({
  name,
  label,
  description,
  isVisible = true
}: {
  name: string
  label?: string
  description?: string
  isVisible?: boolean
}) {
  const form = useFormContext()
  if (!isVisible) {
    return null
  }
  return (
    <FormField
      control={form.control}
      name={name}
      render={({ field }) => (
        <FormItem>
          {label && <FormLabel>{label}</FormLabel>}
          <FormControl>
            <DatetimePicker
              {...field}
              format={[
                ['months', 'days', 'years'],
                ['hours', 'minutes', 'seconds', 'am/pm']
              ]}
            />
          </FormControl>
          <FormDescription>{description}</FormDescription>
          <FormMessage />
        </FormItem>
      )}
    />
  )
}
Repository owner deleted a comment Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant