This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SubmitHandler, useForm } from "react-hook-form"; | |
import { zodResolver } from "@hookform/resolvers/zod"; | |
import { z } from "zod"; | |
const validationSchema = z | |
.object({ | |
firstName: z.string().min(1, { message: "Firstname is required" }), | |
lastName: z.string().min(1, { message: "Lastname is required" }), | |
email: z.string().min(1, { message: "Email is required" }).email({ | |
message: "Must be a valid email", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form className="px-8 pt-6 pb-8 mb-4" onSubmit={handleSubmit(onSubmit)}> | |
<div className="mb-4 md:flex md:justify-between"> | |
<div className="mb-4 md:mr-2 md:mb-0"> | |
<label | |
className="block mb-2 text-sm font-bold text-gray-700" | |
htmlFor="firstName" | |
> | |
First Name | |
</label> | |
<input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Form = () => { | |
const { | |
register, | |
handleSubmit, | |
formState: { errors }, | |
} = useForm<ValidationSchema>({ | |
resolver: zodResolver(validationSchema), | |
}); | |
const onSubmit: SubmitHandler<ValidationSchema> = (data) => console.log(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SubmitHandler, useForm } from "react-hook-form"; | |
import { zodResolver } from "@hookform/resolvers/zod"; | |
import { z } from "zod"; | |
const validationSchema = z | |
.object({ | |
firstName: z.string().min(1, { message: "Firstname is required" }), | |
lastName: z.string().min(1, { message: "Lastname is required" }), | |
email: z.string().min(1, { message: "Email is required" }).email({ | |
message: "Must be a valid email", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const validationSchema = z | |
.object({ | |
firstName: z.string().min(1, { message: "Firstname is required" }), | |
lastName: z.string().min(1, { message: "Lastname is required" }), | |
email: z.string().min(1, { message: "Email is required" }).email({ | |
message: "Must be a valid email", | |
}), | |
password: z | |
.string() | |
.min(6, { message: "Password must be atleast 6 characters" }), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Form from "./Form"; | |
function App() { | |
return ( | |
<div className="max-w-xl mx-auto w-full"> | |
<div className="flex justify-center my-12"> | |
<div className="w-full lg:w-11/12 bg-white p-5 rounded-lg shadow-xl"> | |
<h3 className="pt-4 text-2xl text-center font-bold"> | |
Create New Account |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
const Form = () => { | |
return ( | |
<form className="px-8 pt-6 pb-8 mb-4"> | |
<div className="mb-4 md:flex md:justify-between"> | |
<div className="mb-4 md:mr-2 md:mb-0"> | |
<label | |
className="block mb-2 text-sm font-bold text-gray-700" | |
htmlFor="firstName" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, createContext, useContext } from "react"; | |
//Creating a context | |
const UserContext = createContext(undefined); | |
function App() { | |
const [user, setUser] = useState('John'); | |
return ( | |
<div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
function App() { | |
const [user, setUser] = useState('John'); | |
return ( | |
<div> | |
<NavBar setUser={setUser} /> | |
<MainPage user={user} /> | |
</div> |