JSX 按钮带有类型
注意:此规则包含在以下规则集中:
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
通过将其添加到
deno.json
中的 include
或 exclude
数组中,可以将此规则明确地包含或排除在当前标签中的规则之外。{ "lint": { "rules": { "include": ["jsx-button-has-type"], "exclude": ["jsx-button-has-type"] } } }
强制 <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>;