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: ...@@ -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: Consider a login form where users can input their credentials:
```tsx filename="pages/login.tsx" switcher ```tsx filename="pages/login.tsx" switcher
import { FormEvent } from 'react' import type { SubmitEvent } from 'react'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export default function LoginPage() { export default function LoginPage() {
const router = useRouter() const router = useRouter()
async function handleSubmit(event: FormEvent<HTMLFormElement>) { async function handleSubmit(event: SubmitEvent<HTMLFormElement>) {
event.preventDefault() event.preventDefault()
const formData = new FormData(event.currentTarget) const formData = new FormData(event.currentTarget)
...@@ -432,7 +432,6 @@ export default function LoginPage() { ...@@ -432,7 +432,6 @@ export default function LoginPage() {
``` ```
```jsx filename="pages/login.jsx" switcher ```jsx filename="pages/login.jsx" switcher
import { FormEvent } from 'react'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export default function LoginPage() { export default function LoginPage() {
......
...@@ -163,7 +163,7 @@ export default function NewItemPage() { ...@@ -163,7 +163,7 @@ export default function NewItemPage() {
const [name, setName] = useState('') const [name, setName] = useState('')
const router = useRouter() const router = useRouter()
async function handleSubmit(e: React.FormEvent) { async function handleSubmit(e: React.SubmitEvent<HTMLFormElement>) {
e.preventDefault() e.preventDefault()
const item = await createItem({ name }) const item = await createItem({ name })
setName('') setName('')
...@@ -197,7 +197,7 @@ function ContactForm() { ...@@ -197,7 +197,7 @@ function ContactForm() {
const [status, setStatus] = useState<'idle' | 'success'>('idle') const [status, setStatus] = useState<'idle' | 'success'>('idle')
const shouldReset = useRef(false) const shouldReset = useRef(false)
async function handleSubmit(e: React.FormEvent) { async function handleSubmit(e: React.SubmitEvent<HTMLFormElement>) {
e.preventDefault() e.preventDefault()
await sendMessage({ name }) await sendMessage({ name })
setStatus('success') setStatus('success')
......
...@@ -24,7 +24,9 @@ export function ForgotPasswordForm({ ...@@ -24,7 +24,9 @@ export function ForgotPasswordForm({
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const handleForgotPassword = async (e: React.FormEvent) => { const handleForgotPassword = async (
e: React.SubmitEvent<HTMLFormElement>,
) => {
e.preventDefault(); e.preventDefault();
const supabase = createClient(); const supabase = createClient();
setIsLoading(true); setIsLoading(true);
......
...@@ -26,7 +26,7 @@ export function LoginForm({ ...@@ -26,7 +26,7 @@ export function LoginForm({
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const router = useRouter(); const router = useRouter();
const handleLogin = async (e: React.FormEvent) => { const handleLogin = async (e: React.SubmitEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
const supabase = createClient(); const supabase = createClient();
setIsLoading(true); setIsLoading(true);
......
...@@ -27,7 +27,7 @@ export function SignUpForm({ ...@@ -27,7 +27,7 @@ export function SignUpForm({
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const router = useRouter(); const router = useRouter();
const handleSignUp = async (e: React.FormEvent) => { const handleSignUp = async (e: React.SubmitEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
const supabase = createClient(); const supabase = createClient();
setIsLoading(true); setIsLoading(true);
......
...@@ -24,7 +24,9 @@ export function UpdatePasswordForm({ ...@@ -24,7 +24,9 @@ export function UpdatePasswordForm({
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const router = useRouter(); const router = useRouter();
const handleForgotPassword = async (e: React.FormEvent) => { const handleForgotPassword = async (
e: React.SubmitEvent<HTMLFormElement>,
) => {
e.preventDefault(); e.preventDefault();
const supabase = createClient(); const supabase = createClient();
setIsLoading(true); setIsLoading(true);
......
...@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation' ...@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
export function Search() { export function Search() {
let router = useRouter() let router = useRouter()
function search(event: React.FormEvent<HTMLFormElement>) { function search(event: React.SubmitEvent<HTMLFormElement>) {
event.preventDefault() event.preventDefault()
let input = event.currentTarget.q.value 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