From 442880f2fe6e00623f22a739d036ef3960a9c452 Mon Sep 17 00:00:00 2001 From: Highlander-Maker Date: Wed, 22 Jun 2022 11:11:50 +0100 Subject: [PATCH] add errors to comments section --- package-lock.json | 22 +++++++++++++++++++++ package.json | 1 + pages/post/[slug].tsx | 45 ++++++++++++++++++++++++++++++++++++++++++- yarn.lock | 7 ++++++- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d548629..b1b3d04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "next-sanity": "^0.5.2", "react": "18.1.0", "react-dom": "18.1.0", + "react-hook-form": "^7.32.2", "react-icons": "^4.4.0", "react-portable-text": "^0.4.3" }, @@ -1630,6 +1631,21 @@ "react": "^18.1.0" } }, + "node_modules/react-hook-form": { + "version": "7.32.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.32.2.tgz", + "integrity": "sha512-F1A6n762xaRhvtQH5SkQQhMr19cCkHZYesTcKJJeNmrphiZp/cYFTIzC05FnQry0SspM54oPJ9tXFXlzya8VNQ==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/react-icons": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.4.0.tgz", @@ -3095,6 +3111,12 @@ "scheduler": "^0.22.0" } }, + "react-hook-form": { + "version": "7.32.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.32.2.tgz", + "integrity": "sha512-F1A6n762xaRhvtQH5SkQQhMr19cCkHZYesTcKJJeNmrphiZp/cYFTIzC05FnQry0SspM54oPJ9tXFXlzya8VNQ==", + "requires": {} + }, "react-icons": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.4.0.tgz", diff --git a/package.json b/package.json index 15e2372..3a73cd5 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "next-sanity": "^0.5.2", "react": "18.1.0", "react-dom": "18.1.0", + "react-hook-form": "^7.32.2", "react-icons": "^4.4.0", "react-portable-text": "^0.4.3" }, diff --git a/pages/post/[slug].tsx b/pages/post/[slug].tsx index 2dd81b6..1368c7b 100644 --- a/pages/post/[slug].tsx +++ b/pages/post/[slug].tsx @@ -3,12 +3,26 @@ import Layout from "../../components/Layout"; import { sanityClient, urlFor } from "../../sanity"; import { Post } from "../../typings"; import PortableText from "react-portable-text"; +import { useForm, SubmitHandler } from "react-hook-form"; + +interface IFormInput { + _id: string; + name: string; + email: string; + comment: string; +} interface Props { post: Post; } function Post({ post }: Props) { + const { + register, + handleSubmit, + formState: { errors }, + } = useForm(); + return (
@@ -67,9 +81,19 @@ function Post({ post }: Props) {

Enjoyed this article?

Leave a comment below!

+
+ + +