Skip to content

Commit

Permalink
fix: fix setError bug
Browse files Browse the repository at this point in the history
  • Loading branch information
97vack authored May 8, 2024
1 parent 1bade5f commit 28eeff3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/use/useFormItemContentController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useRef } from 'react';
import { Apis, GlobalProps } from 'react-form-simple/types/form';
import { useController } from 'react-form-simple/use/useController';
import useForceUpdate from 'react-form-simple/use/useForceUpdate';
import { FormUtil } from 'react-form-simple/utils/FormUtil';
import {
Expand Down Expand Up @@ -62,9 +61,7 @@ export function useFormItemContentController(

formUtil.replace({ model: modelValue.current });

const status = useController({ isError: false });

const { isError } = status;
const isError = useRef(false);

const isInitSubscribeEvent = useRef(true);

Expand All @@ -73,7 +70,10 @@ export function useFormItemContentController(
methods.set(value);
});
subscribe.on('onErr', (value) => {
status.isError = isMeaningful(value);
if (isError.current !== isMeaningful(value)) {
forceUpdate(false);
}
isError.current = isMeaningful(value);
});
isInitSubscribeEvent.current = false;
}
Expand All @@ -82,14 +82,14 @@ export function useFormItemContentController(
if (bindId !== preBindId.current) {
modelValue.current = convertStringToObject(bindId, initialValue);
preBindId.current = bindId;
forceUpdate(false)
forceUpdate(false);
}
}, [bindId]);

const methods = {
set(value: any) {
updateProxyValue(modelValue.current, preBindId.current as string, value);
forceUpdate(false)
forceUpdate(false);
},
};

Expand All @@ -112,7 +112,7 @@ export function useFormItemContentController(
value,
checked: Boolean(value),
},
isError,
isError: isError.current,
...apis,
}) || null;

Expand Down

0 comments on commit 28eeff3

Please sign in to comment.