diff --git a/README.md b/README.md index aa05db87..bb9252fa 100644 --- a/README.md +++ b/README.md @@ -74,29 +74,36 @@ TypeScript-first schema validation with static type inference [![npm](https://img.shields.io/bundlephobia/minzip/zod?style=for-the-badge)](https://bundlephobia.com/result?p=zod) -```typescript jsx +> ⚠️ Example below uses the `valueAsNumber`, which requires `react-hook-form` v6.12.0 (released Nov 28, 2020) or later. + +```tsx import React from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; const schema = z.object({ - username: z.string(), + name: z.string().nonempty({ message: 'Required' }), + age: z.number().min(10), }); const App = () => { - const { register, handleSubmit } = useForm({ + const { register, handleSubmit, errors } = useForm({ resolver: zodResolver(schema), }); return (
console.log(d))}> - + {errors.name?.message &&

{errors.name?.message}

} + + {errors.age?.message &&

{errors.age?.message}

}
); }; + +export default App; ``` ### [Superstruct](https://github.com/ianstormtaylor/superstruct) diff --git a/jest.config.js b/jest.config.js index 256eecb8..802905d5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,7 +5,7 @@ module.exports = { }, globals: { 'ts-jest': { - tsConfig: 'tsconfig.jest.json', + tsconfig: 'tsconfig.jest.json', }, }, testMatch: ['**/?(*.)+(spec|test).ts?(x)'],