File tree 8 files changed +13
-12
lines changed
COURSES/core/06-data-fetching
8 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import { VacationsSubLayout } from '~/VacationsSubLayout'
12
12
import { AccountSubLayout } from '~/AccountSubLayout'
13
13
14
14
// Pages
15
- import { BrowseVacationsPage , loader as browseVacationsLoader } from './BrowseVacationsPage'
15
+ import { BrowseVacationsPage , clientLoader as browseVacationsLoader } from './BrowseVacationsPage'
16
16
import { VacationDetailsPage } from './VacationDetailsPage'
17
17
import { LoginPage } from '~/LoginPage'
18
18
import { ErrorPage } from '~/ErrorPage'
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { api } from '~/utils/api'
4
4
import { BrowseVacationsItem } from '~/BrowseVacationsItem'
5
5
import { queryClient } from '~/utils/queryClient'
6
6
7
- export async function loader ( ) {
7
+ export async function clientLoader ( ) {
8
8
const vacations = await queryClient . ensureQueryData ( {
9
9
queryKey : [ 'vacations' ] ,
10
10
queryFn : ( ) => api . vacations . getAll ( ) ,
@@ -14,7 +14,8 @@ export async function loader() {
14
14
}
15
15
16
16
export function BrowseVacationsPage ( ) {
17
- const vacations = useLoaderData ( ) as Awaited < ReturnType < typeof loader > >
17
+ const vacations = useLoaderData ( ) as Awaited < ReturnType < typeof clientLoader > >
18
+
18
19
return (
19
20
< div >
20
21
{ ! vacations && < div > Loading...</ div > }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import type { Vacation } from '~/utils/types'
17
17
// staleTime: 1000 * 30,
18
18
// })
19
19
20
- // export async function loader ({ params }: LoaderFunctionArgs) {
20
+ // export async function clientLoader ({ params }: LoaderFunctionArgs) {
21
21
// return api.vacations.getVacation(vacationId)
22
22
// }
23
23
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { api } from '~/utils/api'
6
6
import type { Vacation } from '~/utils/types'
7
7
8
8
// 2: Finished with loader
9
- export async function loader ( ) {
9
+ export async function clientLoader ( ) {
10
10
return api . vacations . getAll ( )
11
11
}
12
12
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import type { Vacation } from '~/utils/types'
9
9
// 2. Then refactor the code that was fetching within the component to fetch
10
10
// from this loader instead. Note that React Router is already importing this
11
11
// loading and attaching it to the correct route
12
- export async function loader ( ) {
12
+ export async function clientLoader ( ) {
13
13
return [ ]
14
14
}
15
15
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { BrowseVacationsItem } from '~/BrowseVacationsItem'
4
4
import { queryClient } from './utils/queryClient'
5
5
import { useLoaderData } from 'react-router'
6
6
7
- export async function loader ( ) {
7
+ export async function clientLoader ( ) {
8
8
const vacations = await queryClient . fetchQuery ( {
9
9
queryKey : [ 'vacations' ] ,
10
10
queryFn : ( ) => api . vacations . getAll ( ) ,
@@ -13,7 +13,7 @@ export async function loader() {
13
13
return vacations
14
14
}
15
15
16
- type LoaderData = Awaited < ReturnType < typeof loader > >
16
+ type LoaderData = Awaited < ReturnType < typeof clientLoader > >
17
17
18
18
export function BrowseVacationsPage ( ) {
19
19
const vacations = useLoaderData ( ) as LoaderData
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { FavoriteVacationButton } from '~/FavoriteVacationButton'
7
7
import { LoaderFunctionArgs , useLoaderData } from 'react-router'
8
8
import { queryClient } from '~/utils/queryClient'
9
9
10
- export async function loader ( { params } : LoaderFunctionArgs ) {
10
+ export async function clientLoader ( { params } : LoaderFunctionArgs ) {
11
11
const id = parseInt ( params . vacationId ! )
12
12
13
13
const vacation = await queryClient . fetchQuery ( {
@@ -18,7 +18,7 @@ export async function loader({ params }: LoaderFunctionArgs) {
18
18
return vacation
19
19
}
20
20
21
- type LoaderData = Awaited < ReturnType < typeof loader > >
21
+ type LoaderData = Awaited < ReturnType < typeof clientLoader > >
22
22
23
23
export function VacationDetailsPage ( ) {
24
24
const vacation = useLoaderData ( ) as LoaderData
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import { VacationsSubLayout } from '~/VacationsSubLayout'
6
6
import { AccountSubLayout } from '~/AccountSubLayout'
7
7
8
8
// Pages
9
- import { BrowseVacationsPage , loader as browseVacationsLoader } from '~/BrowseVacationsPage'
10
- import { VacationDetailsPage , loader as vacationDetailsLoader } from '~/VacationDetailsPage'
9
+ import { BrowseVacationsPage , clientLoader as browseVacationsLoader } from '~/BrowseVacationsPage'
10
+ import { VacationDetailsPage , clientLoader as vacationDetailsLoader } from '~/VacationDetailsPage'
11
11
import { LoginPage } from '~/LoginPage'
12
12
import { ErrorPage } from '~/ErrorPage'
13
13
import { NotFoundPage } from '~/NotFoundPage'
You can’t perform that action at this time.
0 commit comments