Migré mi aplicación de reaccionar 17.02 para usar la última versión. recientemente de aquí .
Estoy tratando de usar rutas /api para obtener datos en el lado del cliente usando SWR .
lib/fetch
export default async function fetcher(...args) { const res = await fetch(...args); if (!res.ok) throw new Error('Failed to fetch'); return res.json(); } Esto está dentro de /pages/dashboard :
const { data, error } = useSWR(process.env.APP_URL + '/api/user', fetcher, { suspense: true }); const router = useRouter(); useEffect(() => { setUser(data); console.log(series); }, [data, user]); if (error) { router.push('/404'); } return ( <Suspense fallback={<div>Loading...</div>}> <div className="h-screen max-w-7xl mx-auto px-4 bg-background-dark"> <Header title="Dashboard" /> <h1 className="text-5xl text-white">You will see all the series here</h1> </div> </Suspense> ); env.local
APP_URL=http://localhost:3000 La aplicación intenta ir a esta url .
http://localhost:3000/undefined/api/user