模块“react-hook-form”没有导出成员“useForm”

问题描述 投票:0回答:1

这是我下面的代码。 Typescript 给我错误,我尝试安装 @types/react 但仍然相同。请参考下面我的代码。

"use client";

import * as z from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog";

const formSchema = z.object({
  name: z.string().min(1, {
    message: "Server name is required.",
  }),
});

export const InitialModal = () => {
  const form = useForm({
    defaultValus: {
      name: "",
      imageUrl: "",
    },
  });

  return (
    <Dialog open>
      <DialogContent className="bg-white text-black p-0 overflow-hidden">
        <DialogHeader className="pt-8 px-6">
          <DialogTitle className="text-2xl text-center font-bold">
            Customize your server
          </DialogTitle>
          <DialogDescription className="text-center text-zinc-500">
            Give your server a personality with a name and image. You can always
            change it later.
          </DialogDescription>
        </DialogHeader>
      </DialogContent>
    </Dialog>
  );
};

我还尝试从 package.json 更改 typescript 版本。但还是失败了。请帮忙

react-hook-form
1个回答
0
投票

遇到这个问题并通过更改解决了它

"moduleResolution": "bundler"

 "moduleResolution": "node"

在你的

tsconfig.json

请注意,这会使您的应用程序使用节点算法,我不确定它对应用程序有什么影响。

© www.soinside.com 2019 - 2024. All rights reserved.