SkyeYoung commented on code in PR #3152:
URL: https://github.com/apache/apisix-dashboard/pull/3152#discussion_r2234040077


##########
src/components/form/Editor.tsx:
##########
@@ -73,67 +73,63 @@ export const FormItemEditor = <T extends FieldValues>(
   const { t } = useTranslation();
   const { controllerProps, restProps } = genControllerProps(props, '');
   const { customSchema, language, isLoading, ...wrapperProps } = restProps;
-  const { setError, clearErrors } = useFormContext<{
-    [name: string]: object;
-  }>();
-  const customErrorField = `${props.name}-editor`;
-  const { errors } = useFormState({ name: customErrorField });
+  const { trigger } = useFormContext();
+  const monacoErrorRef = useRef<string | null>(null);

Review Comment:
   The original method was to directly use `setError` and `clearError`, which 
would trigger a global update of the form with every input. Also, due to the 
various dependencies on state, it might update multiple times.
   
   Now, using `ref` allows React and RHF to ignore state updates, and only when 
`onValidate` is triggered, actively call `trigger`, which enables RHF to obtain 
an error (ref) once through internal validation logic. This significantly 
reduces the dependencies on state and limits error updates within the component.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to