如何在JSX和Typescript中使用onclick的html属性

如何在JSX和Typescript中使用onclick的html属性,typescript,react-jsx,Typescript,React Jsx,当尝试在我使用的任何HTML元素上使用onclick时,Typesript出现以下错误 ERROR in /Volumes/WorkSpace/Projects/wirecash-client/src/elements/dropdown/Dropdown.tsx (25,45): error TS2339: Property 'onclick' does not exist on type 'HTMLProps<HTMLButtonElement>'. /Volumes/WorkS

当尝试在我使用的任何HTML元素上使用onclick时,Typesript出现以下错误

ERROR in /Volumes/WorkSpace/Projects/wirecash-client/src/elements/dropdown/Dropdown.tsx
(25,45): error TS2339: Property 'onclick' does not exist on type 'HTMLProps<HTMLButtonElement>'.
/Volumes/WorkSpace/Projects/wirecash-client/src/elements/dropdown/dropdown.tsx中出现错误 (25,45):错误TS2339:类型“HTMLProps”上不存在属性“onclick”。 我的组成部分:

import React from 'react'
import { ClientTypes } from 'types'

interface Props {
  items: Array<ClientTypes.DropdownItem>
  onClick(item:ClientTypes.DropdownItem): () => void
}

const Dropdown = ({onClick, items}) => {
  let selectedItem = null;
  for(let i=0, j=items.length; i<j; i++) {
    if(items[i].selected) {
      selectedItem = items[i];
      break;
    }
  }
  return (
    <div className="dropdown show">
      <a className="btn btn-secondary dropdown-toggle" aria-haspopup="true" aria-expanded="false">
        {selectedItem.name}
      </a>

      <div className="dropdown-menu" aria-labelledby="dropdownMenuLink">
        {items.map((item) => (
          <button className="dropdown-item" onclick={onClick(item)}>
            Action
          </button>
        ))}
      </div>
    </div>
  )
}

export default Dropdown
从“React”导入React
从“类型”导入{ClientTypes}
界面道具{
项目:阵列
onClick(项:ClientTypes.DropdownItem):()=>void
}
常量下拉列表=({onClick,items})=>{
让selectedItem=null;
对于(设i=0,j=items.length;i(
行动
))}
)
}
导出默认下拉列表

onclick属性必须是驼峰大小写的
onclick

这管用

<button className="dropdown-item" onClick={() => onClick(item)}>
  Action
</button>
onClick(项目)}>
行动