Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated nested-components example to use App Router #68065

Merged
merged 8 commits into from
Jul 25, 2024
2 changes: 1 addition & 1 deletion examples/nested-components/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Example app using nested components

Taking advantage of the composable nature of React components we can modularize our apps in self-contained, meaningful components. This example has a page under `pages/index.tsx` that uses `components/paragraph.tsx` and `components/post.tsx` that can be styled and managed separately.
Taking advantage of the composable nature of React components we can modularize our apps in self-contained, meaningful components. This example has a page under `app/page.tsx` that uses `app/_components/paragraph.tsx` and `app/_components/post.tsx` that can be styled and managed separately.

## Deploy your own

Expand Down
7 changes: 7 additions & 0 deletions examples/nested-components/app/_components/paragraph.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type ParagraphProps = {
children: React.ReactNode;
};

export default function Paragraph({ children }: ParagraphProps) {
return <p>{children}</p>;
}
7 changes: 7 additions & 0 deletions examples/nested-components/app/_components/post.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.main {
font:
15px Helvetica,
Arial;
border: 1px solid #eee;
padding: 0 10px;
}
15 changes: 15 additions & 0 deletions examples/nested-components/app/_components/post.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import styles from "./post.module.css";

type PostProps = {
title: string;
children: React.ReactNode;
};

export default function Post({ title, children }: PostProps) {
return (
<div className={styles.main}>
<h1>{title}</h1>
{children}
</div>
);
}
24 changes: 24 additions & 0 deletions examples/nested-components/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
h1 {
font-size: 16px;
font-weight: bold;
margin: 10px 0;
}

p {
font:
13px Helvetica,
Arial;
margin: 10px 0;
}

hr {
width: 100px;
border-width: 0;
margin: 20px auto;
text-align: center;
}

hr::before {
content: "***";
color: #ccc;
}
18 changes: 18 additions & 0 deletions examples/nested-components/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "./globals.css";

export const metadata = {
title: "Next.js",
description: "Generated by Next.js",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
5 changes: 5 additions & 0 deletions examples/nested-components/app/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.main {
margin: auto;
max-width: 420px;
padding: 10px;
}
25 changes: 25 additions & 0 deletions examples/nested-components/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import P from "./_components/paragraph";
import Post from "./_components/post";

import styles from "./page.module.css";

export default function Home() {
return (
<div className={styles.main}>
<Post title="My first blog post">
<P>Hello there</P>
<P>This is an example of a componentized blog post</P>
</Post>
<hr />
<Post title="My second blog post">
<P>Hello there</P>
<P>This is another example.</P>
<P>Wa-hoo!</P>
</Post>
<hr />
<Post title="The final blog post">
<P>C’est fin</P>
</Post>
</div>
);
}
19 changes: 0 additions & 19 deletions examples/nested-components/components/paragraph.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions examples/nested-components/components/post.tsx

This file was deleted.

14 changes: 7 additions & 7 deletions examples/nested-components/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"private": true,
"scripts": {
"dev": "next",
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^18.11.5",
"@types/react": "^18.0.23",
"@types/react-dom": "^18.0.7",
"typescript": "^4.8.4"
"@types/node": "^20.14.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"typescript": "^5.5.4"
}
}
47 changes: 0 additions & 47 deletions examples/nested-components/pages/index.tsx

This file was deleted.

Loading