0
  const formRef = useRef(null);
  const [model, setModel] = useState(null);
  const [modal, setModal] = useState(false);
  const [formData, setFormData] = useState<ProjectModel>();

  useEffect(() => {
    let ignore = false;

    if (!ignore) {
      setFormData({ projectName: null });
      setModel(createModel());
    }
    return () => {
      ignore = true
    }
  }, [])



  const formChange = (value: ProjectModel) => {
    const { formContextValue } = formRef && formRef.current || {};

    model.valid = ValidateForm({ model: formContextValue.model, data: value });
    setFormData(value)
  };

  const ModalCreate = ({ state, close }) => {
    return (
      <Modal show={state} onHide={close}>
        <Modal.Header>
          <Modal.Title>Manage Access</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          <Form
            fluid
            onChange={formChange}
            formDefaultValue={formData}
            ref={formRef}
          >
            <FormGroup>
              <ControlLabel>Project Name</ControlLabel>
              <FormControl name="projectName" className="w-full" accepter={Input} />
            </FormGroup>
          </Form>
        </Modal.Body>
        <Modal.Footer>
          <Button onClick={close} appearance="primary">
            Save
    </Button>
          <Button onClick={close} appearance="subtle">
            Cancel
    </Button>
        </Modal.Footer>
      </Modal>
    );
  };
     return <ModalCreate state={modal} close={() => setModal(false)} />;

我在这里遇到一个问题,每次我输入它都会关闭。例如,当我打开模式并尝试输入一些文本或尝试输入时,它会关闭然后打开,然后当我再次尝试输入时,它会关闭然后再次打开。每个字母它会关闭然后打开。如何解决?

4

0 回答 0