deno.com

jsx-button-has-type

注意: 此规则包含在以下规则集中:recommendedreactjsxfresh
deno.json 中启用完整规则集
{
  "lint": {
    "tags": ["recommended"] // ...or "react", "jsx", "fresh"
  }
}
使用 Deno CLI 启用完整规则集
deno lint --tags=recommended
# or ...
deno lint --tags=react
# or ...
deno lint --tags=jsx
# or ...
deno lint --tags=fresh

强制 <button> 元素必须具有 type 属性。如果 <button> 元素放置在 <form> 元素内,它将默认充当提交按钮,这可能会出乎意料。

无效

const btn = <button>click me</button>;
const btn = <button type="2">click me</button>;

有效

const btn = <button type="button">click me</button>;
const btn = <button type="submit">click me</button>;
const btn = <button type={btnType}>click me</button>;
const btn = <button type={condition ? "button" : "submit"}>click me</button>;

您找到所需的内容了吗?

隐私政策