Unverified Commit e3688fbd authored by SamPhillemon's avatar SamPhillemon Committed by GitHub

updated the example of with-three-js to utilize the App Router (#70287)

This PR updates the with-three-js example to use the App Router. Here
are the changes that have been made:

- Renamed the pages folder to the app folder.
- Updated the routing for `/`, `/birds` & `/boxes` files to align with
the App Router.
- Added the `layout.tsx` & `tsconfig.json` file as part of the App
Router.
- Updated the package.json file.

The following actions were performed as part of this PR:

- Ran `pnpm prettier-check `with no issues found.
- Executed the `pnpm check-examples` script.

CC: @samcx

---------
Co-authored-by: 's avatarsamcx <sam@vercel.com>
parent cf590739
"use client";
import { Suspense, useMemo } from "react"; import { Suspense, useMemo } from "react";
import { Canvas } from "@react-three/fiber"; import { Canvas } from "@react-three/fiber";
import { OrbitControls } from "@react-three/drei"; import { OrbitControls } from "@react-three/drei";
import Bird from "../components/Bird"; import Bird from "../_components/Bird";
export default function BirdsPage() { export default function BirdsPage() {
const birds = useMemo( const birds = useMemo(
() => () =>
new Array(10).fill().map((_, index) => { new Array(10).fill(undefined).map((_, index) => {
const x = const x =
(15 + Math.random() * 30) * (Math.round(Math.random()) ? -1 : 1); (15 + Math.random() * 30) * (Math.round(Math.random()) ? -1 : 1);
const y = -10 + Math.random() * 20; const y = -10 + Math.random() * 20;
......
"use client";
import { Canvas } from "@react-three/fiber"; import { Canvas } from "@react-three/fiber";
import { OrbitControls } from "@react-three/drei"; import { OrbitControls } from "@react-three/drei";
import Box from "../components/Box"; import Box from "../_components/Box";
export default function BoxesPage() { export default function BoxesPage() {
return ( return (
......
import "../styles/index.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>
);
}
import Link from "next/link"; import Link from "next/link";
export default function IndexPage() { export default function Home() {
return ( return (
<div className="main"> <div className="main">
<Link href="/birds">Birds Example</Link> <Link href="/birds">Birds Example</Link>
......
...@@ -6,11 +6,17 @@ ...@@ -6,11 +6,17 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@react-three/drei": "9.3.4", "@react-three/drei": "^9.112.1",
"@react-three/fiber": "8.0.10", "@react-three/fiber": "^8.17.7",
"next": "latest", "next": "latest",
"react": "^18.0.0", "react": "^18.3.1",
"react-dom": "^18.0.0", "react-dom": "^18.3.1",
"three": "0.139.2" "three": "^0.168.0"
},
"devDependencies": {
"@types/node": "^22.5.5",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
} }
} }
import "./index.css";
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
export default MyApp;
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment