Telegram-Mini-Apps / TelegramUI

React components library for Telegram Mini Apps inspired by Telegram interface
https://ton.org/mini-apps
MIT License
307 stars 26 forks source link

Using Input component with https://react-hook-form.com/ #56

Closed yalamber closed 3 weeks ago

yalamber commented 1 month ago

When using Input component with react-hook-form we are receiving below error. Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

yalamber commented 1 month ago

What's the difference between FormInput and Input, It seems like FormInput is not exported.

batFormat commented 1 month ago

You can try it like this

  import { Controller, useFormContext } from 'react-hook-form'

  const { control } = useFormContext()

  return (
    <Controller
      name={`blocks.${blockIndex}.items.${itemIndex}.result.answer`}
      control={control}
      render={({ field: { value, onChange } }) => (
        <Input defaultValue={value ?? ''} onChange={onChange} />
      )}
    />
  )
mainsmirnov commented 3 weeks ago

Thank you, issue was fixed in 2.1.8 version