diff --git a/README.md b/README.md index 9fa6f4d..e9fb1b4 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,19 @@ Dead simple Object schema validation. [![npm](https://img.shields.io/bundlephobia/minzip/yup?style=for-the-badge)](https://bundlephobia.com/result?p=yup) +> ⚠️ Pass context via `useForm({ context })`, not via `yupResolver`'s `schemaOptions`. Using React state/atoms via `schemaOptions.context` can result in `undefined` values. + +```typescript jsx +// Correct +useForm({ + resolver: yupResolver(schema), + context: { foo: true }, +}); + +// Avoid - context will be stale/undefined +yupResolver(schema, { context: { foo: true } }); +``` + ```typescript jsx import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup';