Getting Uncaught TypeError: path.split is not a function in react

19

I'm trying to do validations for my form in react. I chose "react-hook-form" library. But I'm constantly getting error "Path.split is not a function. Even after using the default example given in their website, I'm getting the same error. This is the default code given in the official site.

import React from "react";
import { useForm } from "react-hook-form";

export default function App() {
  const { register, handleSubmit, watch, errors } = useForm();
  const onSubmit = data => console.log(data);

  console.log(watch("example")); // watch input value by passing the name of it

  return (
    {/* "handleSubmit" will validate your inputs before invoking "onSubmit" */}
    <form onSubmit={handleSubmit(onSubmit)}>
    {/* register your input into the hook by invoking the "register" function */}
      <input name="example" defaultValue="test" ref={register} />
      
      {/* include validation with required or other standard HTML validation rules */}
      <input name="exampleRequired" ref={register({ required: true })} />
      {/* errors will return when field validation fails  */}
      {errors.exampleRequired && <span>This field is required</span>}
      
      <input type="submit" />
    </form>
  );
}
Share
Improve this question
5
  • Can you share a minimal CodeSandbox that reproduces the issue? – Arun Kumar Mohan Apr 3 at 4:02
  • Hi @ArunKumarMohan Here is the link "codesandbox.io/live/ljesmy8" – Pramod Kumar Apr 3 at 4:58
  • 2
    Looks like you've shared a session URL instead of a CodeSandbox URL. I just answered a similar question here that should fix the issue. Replace ref={register} with {...register('example')}. – Arun Kumar Mohan Apr 3 at 5:10
  • Yeah its working. Thanks @ArunKumarMohan. I didn't see migration docs. – Pramod Kumar Apr 3 at 5:17
  • You're welcome. – Arun Kumar Mohan Apr 3 at 5:18

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

React Native - Image Cache