New
Introducing React Doctor for Enterprise

react-doctor/no-prevent-default

Use `<form action={serverAction}>` (works without JS) or `<button>` instead of `<a>` with preventDefault

  • Category: Correctness
  • Severity: warn
  • Source: oxlint-plugin-react-doctor
  • Framework: global
  • Enabled when: always

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Rule fires on <form onSubmit={handler}> or <a onClick={handler}> whose handler is an inline arrow or function expression containing any .preventDefault() call. <button> is intentionally exempt because <button type='submit'> has a legitimate default action. False positive: a custom Link component that renders as <a> and intercepts navigation for a router the AST cannot see.

Fix prompt

Use this once validation confirms the diagnostic is real.

For forms, replace the JS handler with a Server Action via <form action={serverAction}> so submission works without JavaScript and gets progressive enhancement for free. For anchors, use a <button> when triggering an action or the router's <Link> when navigating — never <a href='#'> with preventDefault(). See https://react.dev/reference/react-dom/components/form

More Correctness rules from the rules reference:

  • react-doctor/no-random-key: Replace the fresh-each-render key with a stable id from the item: key={item.id}
  • react-doctor/no-this-in-sfc: Use the function's `props` parameter instead of `this.props` in stateless function components.
  • react-doctor/no-uncontrolled-input: Pass an explicit initial value to `useState` (e.g. `useState("")` instead of `useState()`), add `onChange` (or `readOnly` to opt out) when you supply `value`, and drop `defaultValue` on controlled inputs — React ignores it
  • react-doctor/no-unsafe: Replace UNSAFE_componentWillMount / WillReceiveProps / WillUpdate with their modern lifecycle equivalents.
  • react-doctor/react-in-jsx-scope: If on React 17+ with the new JSX transform, disable this rule; otherwise import React at the top of the file.