[英]How to fix the Property 'setConfirmDelete' does not exist on type 'JSX.IntrinsicElements' in reactjs
index.tsx索引.tsx
const setConfirmDelete = (state, close) => {
return (
<Modal show={state} onHide={close}>
<Modal.Header>
<Modal.Title>Title</Modal.Title>
</Modal.Header>
<Modal.Body>
'This is a body'
</Modal.Body>
<Modal.Footer>
<Button onClick={close} appearance="primary">
Save
</Button>
<Button onClick={close} appearance="subtle">
Cancel
</Button>
</Modal.Footer>
</Modal>
);
}
export default function Users() {
return (
<div>
<gridTable
....
rowFunc={
[name: 'deleteItem',
onClick: () => {
return (<setConfirmDelete state={modal} close={() => setModal(false)} />)
}
]
}>/<gridTable></div>)}
What I'm trying to do here is to display the modal when I click the function delete, I encounter the error which is the Property 'setConfirmDelete' does not exist on type 'JSX.IntrinsicElements'
.我在这里尝试做的是在单击 function 删除时显示模式,我遇到的错误是Property 'setConfirmDelete' does not exist on type 'JSX.IntrinsicElements'
。
I also tried this code:我也试过这段代码:
onClick={()=> setConfirmDelete({modal, false})
But it doesn't work or display the data但它不起作用或显示数据
This particular error "Property 'setConfirmDelete' does not exist on type 'JSX.IntrinsicElements'" is because React assumes that all lower-case element names are built-in aka "intrinsic" elements.这个特殊的错误“属性 'setConfirmDelete' 在类型 'JSX.IntrinsicElements' 上不存在”是因为 React 假定所有小写元素名称都是内置的,也就是“内在”元素。 All of your components must use uppercase names like SetConfirmDelete
.您的所有组件都必须使用大写名称,例如SetConfirmDelete
。
You cannot return
any JSX from an onClick
.您不能从onClick
return
任何 JSX。 All event handler handler functions are void
and should not return anything.所有事件处理程序处理函数都是void
的,不应返回任何内容。 You must instead set that JSX somewhere using state
.您必须改为使用state
在某处设置JSX。
Let's change your modal
state so that instead of true
/ false
(show/hide) we either store the contents of the modal or false
if there is no modal.让我们更改您的modal
state 以便不是true
/ false
(显示/隐藏),我们要么存储模态的内容,要么如果没有模态则为false
。
Let's make SetConfirmDelete
into a valid React component that takes a close
prop which is a function.让我们把SetConfirmDelete
变成一个有效的 React 组件,它接受一个close
的 prop,它是一个 function。
import React from "react";
import { Modal, Button } from "react-bootstrap";
interface ModalProps {
close: () => void;
// you'll want this is the future
onSubmit: () => void;
}
const ConfirmDeleteModal: React.FC<ModalProps> = ({ close, onSubmit }) => {
return (
<Modal show={true} onHide={close}>
<Modal.Header>
<Modal.Title>Title</Modal.Title>
</Modal.Header>
<Modal.Body>'This is a body'</Modal.Body>
<Modal.Footer>
<Button onClick={onSubmit} appearance="primary">
Save
</Button>
<Button onClick={close} appearance="subtle">
Cancel
</Button>
</Modal.Footer>
</Modal>
);
};
export default function Users() {
// modal state is either an element or false
const [modal, setModal] = React.useState<React.ReactElement | false>(false);
// helper function for setting modal to false
const close = () => setModal(false);
return (
<div>
<div>
<button
onClick={() =>
setModal(
<ConfirmDeleteModal
close={close}
onSubmit={() => console.log("executing delete")}
/>
)
}
>
Delete
</button>
</div>
{
// when the modal is an element, we display it
modal !== false && modal
}
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.