NextJS tutorial
(base) ➜ next-app <git:(main)> ✗ tree --filelimit 20 . . ├── README.md ├── app │ ├── favicon.ico │ ├── globals.css │ ├── layout.tsx │ ├── page.tsx http://localhost:3000 (Root page) │ └── users │ ├── new │ │ └── page.tsx http://localhost:3000/users/new │ └── page.tsx http://localhost:3000/users ├── next-env.d.ts ├── next.config.js ├── node_modules [299 entries exceeds filelimit, not opening dir] ├── package-lock.json ├── package.json ├── postcss.config.js ├── public │ ├── next.svg (Public images, etc) │ └── vercel.svg ├── tailwind.config.ts └── tsconfig.json
JSX is a fancy way of creating a virtual DOM object:
console.log(<div>Hello World</div>) // Prints a virtual DOM object.
ReactDOM.rendor( <div>Hello World</div>, document.getElementById('root');
The page.tsx is transformed to page.ts with proper preprocessing like:
console.log(jsx2js('</dev>Hello World</div>'); // Something like that.
The <Link> Component in React Router is built to handle routing (navigation) on the client side and prevent the web page from reloading for easy navigation. For external links, the anchor tag <a> is still preferable. :
import { Link } from "react-router-dom";
➜ npm i -g create-next-app
➜ npx create-next-app@13.4
Need to install the following packages: create-next-app@13.4.19 Ok to proceed? (y) y ✔ What is your project named? … next-app ✔ Would you like to use TypeScript? … No / Yes ✔ Would you like to use ESLint? … No / Yes ✔ Would you like to use Tailwind CSS? … No / Yes ✔ Would you like to use src/ directory? … No / Yes ✔ Would you like to use App Router? (recommended) … No / Yes ✔ Would you like to customize the default import alias? … No / Yes Creating a new Next.js app in /Users/thava/ws/nextjs/next-app.
Using npm.
Initializing project with template: app-tw
Installing dependencies: A. react B. react-dom C. next D. typescript E. @types/react F. @types/node G. @types/react-dom H. tailwindcss I. postcss J. autoprefixer K. eslint L. eslint-config-next
added 333 packages, and audited 334 packages in 22s
117 packages are looking for funding
run npm fund for detailsfound 0 vulnerabilities npm notice npm notice New patch version of npm available! 10.2.3 -> 10.2.5 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.2.5 npm notice Run npm install -g npm@10.2.5 to update! npm notice Initialized a git repository.
Success! Created next-app at /Users/thava/ws/nextjs/next-app
npm run dev
(base) ➜ npm install -g puppeteer bundle-wizard
npx bundle-wizard https://localhost:3000 --ignoreHTTPSErrors --desktop --port=5000
you can use any of the examples stored at https://github.com/vercel/next.js/tree/canary/examples using the --example option:
npx create-next-app --example blog-starter