[英]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_id
、 company_secret
和onSubmit
。
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.您应该将value
和onChange
道具传递给他们。 You could create a couple of state variables companyId
and companySecret
to manage the input states.您可以创建几个 state 变量companyId
和companySecret
来管理输入状态。
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)}
/>
</>
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.