Altri articoli
Nasze zasady domu

Nasze zasady domu

`useEffect` must be a **synchronous** function that returns either a cleanup function or nothing. If you need to run an async operation you should do it **inside** the effect, not make the effect itself `async`. ```tsx import { useEffect, useState } from 'react'; function MyComponent() { const [data, setData] = useState(null); useEffect(() => { // async work is done inside the effect const fetchData = async () => { const result = await fetchSomeData(); setData(result); }; fetchData(); // optional cleanup return () => { // e.g. cancel a subscription or abort a fetch }; }, []); // dependencies return
{data}
; } ``` Key points 1. **Do not** declare the effect function as `async`. 2. **Do not** return a `Promise` from the effect. 3. Return a cleanup function (or nothing) if you need to clean up. That is the correct way to use `useEffect` in this scenario.

Questo è il nostro sito web e offriamo sempre i prezzi più convenienti qui. Clicca qui per i nostri alloggi o inviaci una domanda personale. oppure inviaci una domanda personale. oppure continua con , oppure vai alla panoramica di tutti gli articoli.

pubblicato 18-12-2025 / Copyright © Guesthouse-Moncarapacho