Skip to content

Commit 226971c

Browse files
committed
fix: avoid clearing previous state when setting errors
1 parent efed0fa commit 226971c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const useAJVForm = <T extends Record<string, any>>(
181181
setState((prevState) =>
182182
Object.keys(newErrors).reduce((updatedState, fieldName) => {
183183
return {
184+
...prevState,
184185
...updatedState,
185186
[fieldName]: {
186187
...prevState[fieldName],

src/useAjvForm.test.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,17 @@ describe('useAJVForm should properly set errors programmatically using setErrors
597597
},
598598
};
599599

600-
const { result } = renderHook(() => useAJVForm(initialData, schema));
600+
const { result } = renderHook(() =>
601+
useAJVForm(
602+
initialData,
603+
schema,
604+
{
605+
userDefinedMessages: {
606+
required: () => 'Monkey message',
607+
},
608+
},
609+
),
610+
);
601611

602612
result.current.setErrors([
603613
{

0 commit comments

Comments
 (0)