utkarsh-1602 / ecommerce-admin

This repository provides a comprehensive solution for managing billboards, categories, and products, allowing you to create a customized online shopping experience similar to Shopify. With intuitive features, you can effortlessly design and organize your store as well.
https://ecommerce-admin-mauve-psi.vercel.app
MIT License
2 stars 0 forks source link

Didn't understand the Full working of zodResolver in product-form.tsx #43

Closed utkarsh-1602 closed 11 months ago

utkarsh-1602 commented 11 months ago

Provide a complete documentation explaining zod Here's the zodResolver used:

import { z } from "zod"
import { zodResolver } from "@hookform/resolvers/zod"

  const form = useForm<ProductFormValues>({
        resolver: zodResolver(formSchema),
        defaultValues: initialData || {
            name: '',
            price: ''
        }
    })
utkarsh-1602 commented 11 months ago

zod is a typescript schema validation, it is used for validating values and elements. In the code, firstly we are Initializing the form using React Hook Form then we are Setting the resolver to handle validation using Zod. Providing default values for the form fields, or an empty string if not available.