Unverified Commit b2490553 authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Replace deprecated React.FormEvent with SubmitEvent (#99821)

## Summary

`@types/react` 19.2.10 deprecates `FormEvent`/`FormEventHandler` (they
don't correspond to a real DOM event). This switches `onSubmit` handlers
to `SubmitEvent<HTMLFormElement>` in test fixtures, the docs
(`authentication.mdx`, `preserving-ui-state.mdx`), and
`examples/with-supabase`. It also removes an unused `FormEvent` import
from a JSX docs sample.

Examples still pinned to `@types/react` 18 are unchanged, since
`SubmitEvent` only exists in `@types/react` >= 19.2.10.

## Verification

- Type-checked the updated fixtures and the docs snippet patterns with
`tsc` (strict) against `@types/react` 19.2.18, plus a negative check
confirming the event type is enforced against `onSubmit`. The fixture
files aren't in the root `tsconfig.json` include list, so `pnpm
typescript` doesn't cover them.

<!-- NEXT_JS_LLM -->
parent 1dd198b6
......@@ -395,13 +395,13 @@ Here are the steps to implement a sign-up and/or login form:
Consider a login form where users can input their credentials:
```tsx filename="pages/login.tsx" switcher
import { FormEvent } from 'react'
import type { SubmitEvent } from 'react'
import { useRouter } from 'next/router'
export default function LoginPage() {
const router = useRouter()
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
async function handleSubmit(event: SubmitEvent<HTMLFormElement>) {
event.preventDefault()
const formData = new FormData(event.currentTarget)
......@@ -432,7 +432,6 @@ export default function LoginPage() {
```
```jsx filename="pages/login.jsx" switcher
import { FormEvent } from 'react'
import { useRouter } from 'next/router'
export default function LoginPage() {
......
......@@ -163,7 +163,7 @@ export default function NewItemPage() {
const [name, setName] = useState('')
const router = useRouter()
async function handleSubmit(e: React.FormEvent) {
async function handleSubmit(e: React.SubmitEvent<HTMLFormElement>) {
e.preventDefault()
const item = await createItem({ name })
setName('')
......@@ -197,7 +197,7 @@ function ContactForm() {
const [status, setStatus] = useState<'idle' | 'success'>('idle')
const shouldReset = useRef(false)
async function handleSubmit(e: React.FormEvent) {
async function handleSubmit(e: React.SubmitEvent<HTMLFormElement>) {
e.preventDefault()
await sendMessage({ name })
setStatus('success')
......
......@@ -24,7 +24,9 @@ export function ForgotPasswordForm({
const [success, setSuccess] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const handleForgotPassword = async (e: React.FormEvent) => {
const handleForgotPassword = async (
e: React.SubmitEvent<HTMLFormElement>,
) => {
e.preventDefault();
const supabase = createClient();
setIsLoading(true);
......
......@@ -26,7 +26,7 @@ export function LoginForm({
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const handleLogin = async (e: React.FormEvent) => {
const handleLogin = async (e: React.SubmitEvent<HTMLFormElement>) => {
e.preventDefault();
const supabase = createClient();
setIsLoading(true);
......
......@@ -27,7 +27,7 @@ export function SignUpForm({
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const handleSignUp = async (e: React.FormEvent) => {
const handleSignUp = async (e: React.SubmitEvent<HTMLFormElement>) => {
e.preventDefault();
const supabase = createClient();
setIsLoading(true);
......
......@@ -24,7 +24,9 @@ export function UpdatePasswordForm({
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const handleForgotPassword = async (e: React.FormEvent) => {
const handleForgotPassword = async (
e: React.SubmitEvent<HTMLFormElement>,
) => {
e.preventDefault();
const supabase = createClient();
setIsLoading(true);
......
......@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
export function Search() {
let router = useRouter()
function search(event: React.FormEvent<HTMLFormElement>) {
function search(event: React.SubmitEvent<HTMLFormElement>) {
event.preventDefault()
let input = event.currentTarget.q.value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment