简体   繁体   English

警告:validateDOMNesting(…):<form> 不能通过使用语义-ui-react 模态显示为的后代</form>

[英]Warning: validateDOMNesting(…): <form> cannot appear as a descendant of <form> by using semantic-ui-react modal

When I use Form in modal of semantic-ui-react , it shows that error.当我在semantic-ui-react的模态中使用Form时,它会显示该错误。

Warning: validateDOMNesting(…) : cannot appear as a descendant of警告: validateDOMNesting(…) : 不能作为后代出现

I know it is show if there are form in form.我知道如果表格中有表格,那就是表演。

Below is my code, there are no one.下面是我的代码,没有人。 if i don't use modal, there are no error.如果我不使用模态,则没有错误。

import { useState } from "react";
import { Helmet } from "react-helmet";
import { Button, Modal, Form } from "semantic-ui-react";
import { Body, Wrapper, Content, Article } from "../../Styles/Wrapper";

// eslint-disable-next-line import/no-anonymous-default-export
export default (company_id, company_secret, onSubmit) => {
  const [open, setOpen] = useState(false);

  return (
    <Body>
      <Wrapper>
        <Helmet>
          <title>juju</title>
        </Helmet>
        <Content>
          <Article>
            <Modal as={Form}
              onClose={() => setOpen(false)}
              onOpen={() => setOpen(true)}
              open={open}
              trigger={
                <Button
                  style={{ marginBottom: 10, backgroundColor: "#FEE500" }}
                  size="large"
                  fluid
                >
                  <span style={{ fontSize: 15 }}>begin</span>
                </Button>
              }
            >
              <Modal.Header>add</Modal.Header>
              <Modal.Content>
                <Form onSubmit={onSubmit}>
                  <Form.Group>
                    <Form.Input
                      placeholder="put id"
                      name="id"
                      {...company_id}
                    />
                    <Form.Input
                      placeholder="put secret"
                      name="secret"
                      {...company_secret}
                    />
                    <Form.Button content="Submit" />
                  </Form.Group>
                </Form>
              </Modal.Content>
            </Modal>
          </Article>
        </Content>
      </Wrapper>
    </Body>
  );
};

You cannot have a form inside a form . form中不能有form Remove as={Form} when rendering the Modal component.渲染Modal组件时移除as={Form} You should also fix the function arguments since the component receives a props object.您还应该修复 function arguments,因为该组件接收props object。 You should destructure company_id , company_secret , and onSubmit .您应该解构company_idcompany_secretonSubmit

export default ({ company_id, company_secret, onSubmit }) => {
  // ...
}

And there are a few issues with the <Form.Input> components. <Form.Input>组件存在一些问题。 You should pass them the value and onChange props.您应该将valueonChange道具传递给他们。 You could create a couple of state variables companyId and companySecret to manage the input states.您可以创建几个 state 变量companyIdcompanySecret来管理输入状态。

const [companyId, setCompanyId] = useState(company_id)
const [companySecret, setCompanySecret] = useState(company_secret)
<>
  <Form.Input
    name="id"
    value={companyId}
    onChange={(e) => setCompanyId(e.target.value)}
  />
  <Form.Input
    name="secret"
    value={companySecret}
    onChange={(e) => setCompanySecret(e.target.value)}
  />
</>

编辑语义-ui-modal-fz1su

PS I would suggest using camelCase variables everywhere (unless you absolutely have to use snake_case ) for consistency. PS 我建议在任何地方使用camelCase变量(除非你绝对必须使用snake_case )以保持一致性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:validateDOMNesting(...): <form> 不能作为 <form> - Warning: validateDOMNesting(…): <form> cannot appear as a descendant of <form> 警告:validateDOMNesting(...):<a>不能作为后代出现</a> - Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a> React --&gt; 警告:validateDOMNesting(...):<p> 不能作为后代出现<p> - React --> Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <p> 使用 Semantic-UI-React 进行表单验证 - Form Validation with Semantic-UI-React 使用自定义组件作为语义UI反应模式中的触发器 - Using Custom Component as trigger in semantic-ui-react modal index.js:1 警告:validateDOMNesting(...):<ul> 不能作为后代出现<p></p></ul> - index.js:1 Warning: validateDOMNesting(...): <ul> cannot appear as a descendant of <p> Semantic-UI-React:Form.Field 正在破坏布局 - Semantic-UI-React: Form.Field is breaking layout 无法使用语义 ui-react 减少 reactjs 中标签的 fontSize - Cannot reduce the fontSize of label in reactjs using semantic-ui-react React Semantic UI 无法在 Modal 中提交表单 - React Semantic UI cannot submit a form inside Modal 如何修复此警告 - 警告:validateDOMNesting(...): <a>cannot appear as a descendant of</a> <a>.</a> <a>下面是我的代码</a> - How do I fix this warning- Warning: validateDOMNesting(…): <a> cannot appear as a descendant of <a>. below is my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM