Prechádzať zdrojové kódy

fix: 关闭modal时表单重置

lanjianrong 2 rokov pred
rodič
commit
4f1b56f621
1 zmenil súbory, kde vykonal 9 pridanie a 2 odobranie
  1. 9 2
      src/components/Modal/index.tsx

+ 9 - 2
src/components/Modal/index.tsx

@@ -6,13 +6,15 @@ import React, {
   useCallback,
   useState,
   useImperativeHandle,
-  useId
+  useId,
+  useTransition
 } from 'react'
 import { Modal, Form } from 'antd'
 import type { ModalProps } from 'antd'
 
 const MyModal = memo(
   forwardRef((prop: any, ref) => {
+    const [, startTransition] = useTransition()
     const [form] = Form.useForm()
     const [modalChildren, setModalChildren] = useState<React.ReactElement>(null)
     const [loading, setLoading] = useState(false)
@@ -49,9 +51,14 @@ const MyModal = memo(
         ...source,
         visible: false
       }))
+      startTransition(() => {
+        if (typeRef.current === 'form') {
+          form.resetFields()
+        }
+      })
     }, [form])
 
-    // 关闭当前Modal
+    // 打开当前Modal
     const onOpen = useCallback(() => {
       setModalProps(source => ({
         ...source,