Open History to see the last commit
1import { useEffect, useState } from 'react'
2β
3import { createFileRoute } from '@tanstack/react-router'
4import { emitRouteNavigation } from '../../devtools'
5β
6function getNames() {
7 return fetch('/demo/api/names').then((res) => res.json() as Promise<string[]>)
8}
9β
10export const Route = createFileRoute('/demo/start/api-request')({
11 component: Home,
12 beforeLoad: () => {
13 console.log('Before loading Start API Request Demo route')
14 },
15 loader: () => {
16 console.log('Navigated to Start API Request Demo')
17 emitRouteNavigation('API Request', '/demo/start/api-request')
18 },
19})
20β
21function Home() {
22 const [names, setNames] = useState<Array<string>>([])
23β
24 useEffect(() => {
25 getNames().then(setNames)
26 }, [])
27β
28 return (
29 <div
30 className="flex items-center justify-center min-h-screen p-4 text-white"
31 style={{
32 backgroundColor: '#000',
33 backgroundImage:
34 'radial-gradient(ellipse 60% 60% at 0% 100%, #444 0%, #222 60%, #000 100%)',
35 }}
36 >
37 <div className="w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10">
38 <h1 className="text-2xl mb-4">Start API Request Demo - Names List</h1>
39 <ul className="mb-4 space-y-2">
40 {names.map((name) => (
41 <li
42 key={name}
43 className="bg-white/10 border border-white/20 rounded-lg p-3 backdrop-blur-sm shadow-md"
44 >
45 <span className="text-lg text-white">{name}</span>
46 </li>
47 ))}
48 </ul>
49 </div>
50 </div>
51 )
52}