Skip to content

Commit 01dc431

Browse files
committed
update 06-client-side-rendering
1 parent 7c0891c commit 01dc431

23 files changed

Lines changed: 87 additions & 83 deletions

File tree

04-frameworks/08-nextjs/03-boilerplate/src/app/cars/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const CarsLayout = (props: Props) => {
2222
</Link>
2323
<h1 className={classes.title}>Rent a car</h1>
2424
</nav>
25-
<main className={classes.content}>{children}</main>
25+
<div className={classes.content}>{children}</div>
2626
</>
2727
);
2828
};

04-frameworks/08-nextjs/04-static-site-generation/src/app/cars/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CarsLayout = (props: Props) => {
1717
</Link>
1818
<h1 className={classes.title}>Rent a car</h1>
1919
</nav>
20-
<main className={classes.content}>{children}</main>
20+
<div className={classes.content}>{children}</div>
2121
</>
2222
);
2323
};

04-frameworks/08-nextjs/05-server-side-rendering/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@ export default CarPage;
138138
```
139139

140140
> All options will re-render the component on each refresh (F5)
141-
141+
>
142142
> `cache: 'force-cache'`: will fetch data only once.
143-
143+
>
144144
> `cache: 'no-store'`: will fetch data on each refresh (F5).
145-
145+
>
146146
> `next: { revalidate: 10 },`: will fetch data on each refresh (F5) after revalidate seconds.
147+
>
148+
> An advanced option is to use [Cache Components or also named Partial Prerendering](https://nextjs.org/docs/app/getting-started/cache-components)
147149
148150
# About Basefactor + Lemoncode
149151

04-frameworks/08-nextjs/05-server-side-rendering/src/app/cars/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CarsLayout = (props: Props) => {
1717
</Link>
1818
<h1 className={classes.title}>Rent a car</h1>
1919
</nav>
20-
<main className={classes.content}>{children}</main>
20+
<div className={classes.content}>{children}</div>
2121
</>
2222
);
2323
};

04-frameworks/08-nextjs/06-client-side-rendering/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _./src/pods/car/api/car.api.ts_
3030

3131
export const bookCar = async (car: Car): Promise<boolean> => {
3232
await fetch(`${url}/${car.id}`, {
33-
method: 'PUT',
33+
method: 'PATCH',
3434
headers: { 'Content-Type': 'application/json' },
3535
body: JSON.stringify(car),
3636
});
@@ -88,7 +88,7 @@ IMAGES_DOMAIN=localhost
8888
_./src/core/constants/env.constants.ts_
8989

9090
```diff
91-
export const envConstants = {
91+
export const ENV = {
9292
- BASE_API_URL: process.env.BASE_API_URL,
9393
+ BASE_API_URL: process.env.NEXT_PUBLIC_BASE_API_URL,
9494
BASE_PICTURES_URL: process.env.BASE_PICTURES_URL,
@@ -132,7 +132,7 @@ import { Inter } from 'next/font/google';
132132
+ theme.primary === lightTheme.primary ? darkTheme : lightTheme;
133133
+ setTheme(newTheme);
134134
+ };
135-
+
135+
+
136136
+ return (
137137
+ <ThemeContext.Provider value={{ theme, onToggleThemeMode }}>
138138
+ {children}
@@ -154,8 +154,9 @@ const RootLayout = (props: Props) => {
154154
return (
155155
<html lang="en" className={inter.className}>
156156
<body>
157-
- {children}
158-
+ <ThemeProvider>{children}</ThemeProvider>
157+
+ <ThemeProvider>
158+
<main>{children}</main>
159+
+ </ThemeProvider>
159160
</body>
160161
</html>
161162
);
@@ -169,7 +170,7 @@ It throws the error: `TypeError: createContext only works in Client Components.
169170

170171
_./src/core/theme.context.tsx_
171172

172-
```jsx
173+
```tsx
173174
'use client';
174175
import React from 'react';
175176

@@ -206,10 +207,9 @@ export const ThemeProvider = ({ children }) => {
206207
</ThemeContext.Provider>
207208
);
208209
};
209-
210210
```
211211

212-
> You cannot use a ServerComponent inside Client Component but [you can pass a Server Component as prop](https://nextjs.org/docs/getting-started/react-essentials#nesting-server-components-inside-client-components).
212+
You cannot use a ServerComponent inside Client Component but you can pass a Server Component as prop:
213213

214214
_./src/app/layout.tsx_
215215

@@ -238,7 +238,7 @@ import { Inter } from 'next/font/google';
238238
- theme.primary === lightTheme.primary ? darkTheme : lightTheme;
239239
- setTheme(newTheme);
240240
- };
241-
-
241+
-
242242
- return (
243243
- <ThemeContext.Provider value={{ theme, onToggleThemeMode }}>
244244
- {children}
@@ -261,7 +261,7 @@ Using theme:
261261

262262
_./src/pods/car-list/components/nav.component.tsx_
263263

264-
```jsx
264+
```tsx
265265
'use client';
266266
import { ThemeContext } from '#core/theme.context';
267267
import React from 'react';
@@ -286,13 +286,12 @@ export const Nav: React.FC<Props> = (props) => {
286286
</nav>
287287
);
288288
};
289-
290289
```
291290

292291
_./src/pods/car-list/components/index.ts_
293292

294293
```diff
295-
export * from './car-list.component';
294+
export * from './car-item.component';
296295
+ export * from './nav.component';
297296

298297
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
import "./.next/dev/types/routes.d.ts";
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

04-frameworks/08-nextjs/06-client-side-rendering/next.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { NextConfig } from 'next';
2+
3+
const nextConfig: NextConfig = {
4+
images: {
5+
dangerouslyAllowLocalIP: true, // only for local development
6+
remotePatterns: [
7+
{
8+
hostname: process.env.IMAGES_DOMAIN,
9+
},
10+
],
11+
},
12+
};
13+
14+
export default nextConfig;
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"name": "07-nextjs-examples",
2+
"name": "nextjs-examples",
33
"version": "1.0.0",
44
"description": "Nextjs examples",
5+
"type": "module",
6+
"imports": {
7+
"#*": "./src/*"
8+
},
59
"scripts": {
610
"start": "run-p -l start:dev start:api-server",
711
"start:dev": "next dev",
@@ -10,24 +14,21 @@
1014
"start:api-server": "cd api-server && npm run mock-server",
1115
"postinstall": "cd ./api-server && npm install"
1216
},
13-
"imports": {
14-
"#*": "./src/*"
15-
},
1617
"author": "Lemoncode",
1718
"license": "MIT",
1819
"dependencies": {
19-
"next": "^15.1.6",
20+
"next": "^16.0.10",
2021
"normalize.css": "^8.0.1",
21-
"react": "^19.0.0",
22-
"react-dom": "^19.0.0",
23-
"sharp": "^0.33.5"
22+
"react": "^19.2.3",
23+
"react-dom": "^19.2.3",
24+
"sharp": "^0.34.5"
2425
},
2526
"devDependencies": {
26-
"@types/node": "22.13.1",
27-
"@types/react": "^19.0.8",
28-
"@types/react-dom": "^19.0.3",
27+
"@types/node": "25.0.1",
28+
"@types/react": "^19.2.7",
29+
"@types/react-dom": "^19.2.3",
2930
"npm-run-all": "^4.1.5",
30-
"rimraf": "^6.0.1",
31-
"typescript": "^5.7.3"
31+
"rimraf": "^6.1.2",
32+
"typescript": "^5.9.3"
3233
}
3334
}

04-frameworks/08-nextjs/06-client-side-rendering/src/app/cars/[carId]/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React from 'react';
2-
import { Metadata } from 'next';
31
import { Car, api, mapCarFromApiToVm } from '#pods/car';
2+
import { Metadata } from 'next';
43

54
interface Props {
65
params: Promise<{ carId: string }>;

0 commit comments

Comments
 (0)