简体   繁体   English

如何修复 reactjs 中类型“JSX.IntrinsicElements”上不存在属性“setConfirmDelete”

[英]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>
  );
}

Code Sandbox Link 代码沙盒链接

暂无
暂无

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

相关问题 类型“JSX.IntrinsicElements”上不存在属性“元素” - Property 'element' does not exist on type 'JSX.IntrinsicElements' 类型“JSX.IntrinsicElements”上不存在属性。 TS2339 - Property does not exist on type 'JSX.IntrinsicElements'. TS2339 “JSX.IntrinsicElements”类型上不存在属性“mesh” - Property 'mesh' does not exist on type 'JSX.IntrinsicElements' 使用本机Web组件时出现打字稿错误“类型&#39;JSX.IntrinsicElements&#39;上不存在属性” - Typescript error “Property does not exist on type 'JSX.IntrinsicElements'” when using native web component “JSX.IntrinsicElements”类型上不存在属性“stripe-pricing-table” - Property 'stripe-pricing-table' does not exist on type 'JSX.IntrinsicElements' 如何修复 Typescript 中的“元素”类型错误不存在属性? - How to fix property does not exist on type 'Element' error in Typescript? 离子3中“对象”类型中不存在如何修复属性? - how to fix property does not exist on type 'Object' in ionic 3? 如何修复“类型&#39;typeof firestore&#39;上不存在属性&#39;getAll&#39;” - How to fix "Property 'getAll' does not exist on type 'typeof firestore'" 如何修复 typeScript 中的“对象”类型上不存在“属性”拨号 - how to fix 'Property 'dials' does not exist on type 'Object' in typeScript Reactjs Typerscript:类型“ never”上不存在属性“ toLowerCase” - Reactjs Typerscript: Property 'toLowerCase' does not exist on type 'never'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM