jsx-button-has-type
注意: 此规则包含在以下规则集中:
recommended
react
jsx
fresh
在
deno.json
中启用完整集合:{ "lint": { "rules": { "tags": ["recommended"] // ...or "react", "jsx", "fresh" } } }
使用 Deno CLI 启用完整集合:
deno lint --rules-tags=recommended # or ... deno lint --rules-tags=react # or ... deno lint --rules-tags=jsx # or ... deno lint --rules-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>;