question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: React-hook-Form v7 for ionic-react 6 IonInput props is not assignable

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

IonInput is not assigning types of props using register function of react-hook-form

Expected Behavior

props of register function using react-hook-form should be assignable to IonInput

Steps to Reproduce

import { useForm } from ‘react-hook-form’;

const { control, handleSubmit, register, setValue } = useForm({ defaultValues: { email: ‘’ } });

const {ref, onChange, …props} = register(‘email’, { required: true, })

<IonItem>
  <IonLabel>Email</IonLabel>
      <IonInput  {...props} />         
  </IonItem>

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/Users/joeldacuma/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/react 6.0.1

Capacitor:

Capacitor CLI : 2.4.6 @capacitor/android : 2.4.6 @capacitor/core : 2.4.6 @capacitor/ios : 2.4.6

Utility:

cordova-res : not installed globally native-run : not installed globally

System:

NodeJS : v14.17.0 npm : 6.14.13 OS : macOS Monterey

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
joeldacumacommented, Jan 5, 2022

Hello @joeldacuma thanks for reporting this issue.

Can you help explain to me the reasoning behind why ion-input should have the exact type signature as react-hook-form?

In your pseudo code you have left out what props is tied to, so I’m having a difficult time following the example.

An example repository would be great to visualize the issue.

Hi @sean-perkins ,

there is a compatibility issue for the max property for react-hook-form and IonInput for Ionic 6. This is working fine using Ionic 5 with react-hook-form v7.

Here is the reference for Ionic5 react-hook-form v7: https://github.com/alanmontgomery/ionic-react-hook-form-example/blob/main/src/pages/Home.js

Here is the error I encountered in Ionic6:

Screen Shot 2022-01-05 at 1 01 44 PM
1reaction
sean-perkinscommented, Jan 12, 2022

Thanks for the extra detail. I’m unable to pinpoint a specific change in v6 that would have regressed this behavior. The type signature for min/max has aligned with the HTML Spec for being a string | date (date string) since April 2018.

It looks like the type signature from the implementation using react-hook-form is incorrect (string | number | undefined).

Could you isolate this behavior in a repository, with a branch on v5 and a branch on v6?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IonInput getting error with React Hook Form - Stack Overflow
Type 'number' is not assignable to type 'string | undefined'. My Dependencies: @ionic/react": "^6.0.0"; react-hook-form": "^7.27 ...
Read more >
Migrate From V6 to V7 - Simple React forms validation
V6 to V7. Hi there,. React Hook Form focus on the following aspect on Version 7: ... The Controller component rules prop no...
Read more >
Forms And Validation In Ionic React - Smashing Magazine
In this tutorial, you will learn how to build forms when working with Ionic React and how to make these forms interactive by...
Read more >
Using React Hook Form v7 with Ionic Framework ... - YouTube
ionic #reactjs #hookform Using React Hook Form v7 with Ionic Framework React Components. This is an updated example of a video and a ......
Read more >
React Hook Form V7 with Material UI and Typescript Tutorial
In this video, I will help install and understand the basics of React-Hook-Form, a library that makes working with forms an absolute breeze....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found