DocumentationRulesno-missing-button-type

no-missing-button-type

Full Name in eslint-plugin-react-dom

react-dom/no-missing-button-type

Full Name in @eslint-react/eslint-plugin

@eslint-react/dom/no-missing-button-type

Features

🔍

Presets

  • dom
  • recommended
  • recommended-typescript
  • recommended-type-checked

What it does

Enforces explicit type attribute for button elements.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.

Allowed button types are: submit, button or reset.

Examples

Failing

import React from "react";
 
function MyComponent() {
  return <button>Click me</button>;
  //     ^^^^^^^^^^^^^^^^^^^^^^^^^
  //     - Missing 'type' attribute on button component.
}

Passing

import React from "react";
 
function MyComponent() {
  return <button type="button">Click me</button>;
}

Implementation

Further Reading