Skip to content

Commit 25adc7c

Browse files
committed
docs: clarify yupResolver context usage in README
1 parent 2e9bc7c commit 25adc7c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ Dead simple Object schema validation.
147147

148148
[![npm](https://img.shields.io/bundlephobia/minzip/yup?style=for-the-badge)](https://bundlephobia.com/result?p=yup)
149149

150+
> ⚠️ Pass context via `useForm({ context })`, not via `yupResolver`'s `schemaOptions`. Using React state/atoms via `schemaOptions.context` can result in stale/undefined values.
151+
152+
```typescript jsx
153+
// Correct
154+
useForm({
155+
resolver: yupResolver(schema),
156+
context: { foo: true },
157+
});
158+
159+
// Avoid - context will be stale/undefined
160+
yupResolver(schema, { context: { foo: true } });
161+
```
162+
150163
```typescript jsx
151164
import { useForm } from 'react-hook-form';
152165
import { yupResolver } from '@hookform/resolvers/yup';

0 commit comments

Comments
 (0)