Last active
September 5, 2025 14:57
-
-
Save misostack/85b1a85212257d0d2a006a381198488e to your computer and use it in GitHub Desktop.
Revisions
-
Nguyen Minh Son revised this gist
Sep 18, 2022 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -264,3 +264,10 @@ export const getStaticProps: GetStaticProps<{ page: PageModel }> = async ({ }; ``` ### NextJS Environment  - .env.[NODE_ENV] to load environment variables - Expose environment variables to the browser by prefixing with NEXT_PUBLIC_ -
Nguyen Minh Son revised this gist
Sep 17, 2022 . 1 changed file with 49 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -215,3 +215,52 @@ export const getServerSideProps: GetServerSideProps<{  ### getStaticPaths and getStaticProps  ```ts import { GetStaticPaths, GetStaticProps } from "next"; import { useRouter } from "next/router"; import { PageModel } from "../business/models"; import Page from "../components/page"; export default (props: { page: PageModel }) => { const router = useRouter(); const { page } = props; if (router.isFallback) { return <div>Loading...</div>; } //const { pageSlug } = router.query; return <Page page={page}></Page>; }; export const getStaticPaths: GetStaticPaths = async () => { const paths = [{ params: { pageSlug: "lien-he" } }]; return { paths, // don't build static page at build time, keep it for the 1st request // to reduce build time fallback: true, }; }; export const getStaticProps: GetStaticProps<{ page: PageModel }> = async ({ params, }) => { const pageSlug = (params["pageSlug"] as string) || ""; const page: PageModel = { title: `Page with slug = ${pageSlug}`, slug: pageSlug, content: `Content of page with slug = ${pageSlug}`, featureImage: "", id: Math.random().toFixed(), }; return { props: { page, }, }; }; ``` -
Nguyen Minh Son revised this gist
Sep 16, 2022 . 1 changed file with 40 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -164,6 +164,8 @@ export default Layout; ### getServerSideProps #### Return Props ```ts export async function getServerSideProps(context) { return { @@ -174,4 +176,42 @@ export async function getServerSideProps(context) {  #### 404 Notfound  ```ts export const getServerSideProps: GetServerSideProps<{ category: BlogCategoryModel; }> = async (context) => { const { query } = context; const categorySlug = query.categorySlug; if (categorySlug === "posts") { return { notFound: true, }; } const category: BlogCategoryModel = { title: `Category [${categorySlug}]`, posts: Array.from(new Array(6)).map((_, idx) => { return { title: `Post ${++idx}`, content: "", id: "1", featureImage: "", slug: "post-1", }; }), }; return { props: { category }, }; }; ``` #### Redirect  -
Nguyen Minh Son revised this gist
Sep 15, 2022 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -160,3 +160,18 @@ export default Layout; ``` ## Data Fetching ### getServerSideProps ```ts export async function getServerSideProps(context) { return { props: {}, // will be passed to the page component as props } } ```  -
Nguyen Minh Son revised this gist
Sep 14, 2022 . 1 changed file with 61 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,3 +99,64 @@ Similar to CDNs, Edge servers are distributed to multiple locations around the w  ### Layouts  The main idea is creating a layout component which will wrap your page component. We can use the hierarchy file structure in nextjs to apply this pattern ```tsx // pages/_document.tsx import { Html, Head, Main, NextScript } from "next/document"; export default function Document() { return ( <Html lang="vi"> <Head /> <body> <Main /> <NextScript /> </body> </Html> ); } // pages/_app.tsx import type { ReactElement, ReactNode } from "react"; import type { NextPage } from "next"; import type { AppProps } from "next/app"; import "../styles/global.scss"; export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & { getLayout?: (page: ReactElement) => ReactNode; }; type AppPropsWithLayout = AppProps & { Component: NextPageWithLayout; }; export default function MyApp({ Component, pageProps }: AppPropsWithLayout) { // Use the layout defined at the page level, if available const getLayout = Component.getLayout ?? ((page) => page); return getLayout(<Component {...pageProps} />); } // components/layout-default.tsx import Meta from "./partials/meta-head"; const Layout = ({ children }) => { return ( <> <Meta /> <main>{children}</main> </> ); }; export default Layout; ``` -
Nguyen Minh Son revised this gist
Sep 9, 2022 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -90,3 +90,12 @@ NestJS use [SWC](https://swc.rs/) to replace Babel as a compiled tool. ### The Edge Similar to CDNs, Edge servers are distributed to multiple locations around the world. But unlike CDNs, which store static content, some Edge servers can run code. ## Pages & Links ### NextJS Page Routes   -
Nguyen Minh Son revised this gist
Sep 9, 2022 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -81,5 +81,12 @@ NestJS use [SWC](https://swc.rs/) to replace Babel as a compiled tool.  > Next.js **pre-renders** every page by **default** ### Content Delivery Networks ( CDN )  ### The Edge Similar to CDNs, Edge servers are distributed to multiple locations around the world. But unlike CDNs, which store static content, some Edge servers can run code. -
Nguyen Minh Son revised this gist
Sep 9, 2022 . 1 changed file with 43 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,4 +40,46 @@ NestJS use [SWC](https://swc.rs/) to replace Babel as a compiled tool. ### BuildTime vs Runtime > BuildTime: is giving name for a series of steps that transform application's code into production-optimized files to be deployed on server and consumed by users includes: - HTML Files for static generated pages - Javascript code for rendering pages on the server - JavaScript code for making pages interactive on the client - CSS Files  > Runtime: refers to the period of time when your application runs in response to a user's request ### Rendering on Client/Server > Rendering: convert your reactjs code into HTML representation of your UI. Can be happened in - Client Side - Client Side Rendering - A head of time at build time - Static Side Generation ( Pre-Rendering ) - Server Side - Every request at runtime - Server Side Rendering ( Pre-Rendering ) **Pre-Rendering**  **Client-Side-Rendering**   **Server-Side-Rendering**  **Static-Side-Generation**  **Can you have multiple rendering methods into a single next.js application?**  > Next.js **pre-renders** every page by **default** -
Nguyen Minh Son revised this gist
Sep 9, 2022 . 1 changed file with 37 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,42 @@ npx create-next-app seo --use-yarn --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter" ## Overview Architecture  > Main Concept ### Development vs Production **Development stage:** TypeScript and ESLint integration, Fast Refresh, ... **Production stage:** Compiled, Bundled, Minified and Code Split  > Compiled : JSX -> should be transformed to JS version that browser can understand  NestJS use [SWC](https://swc.rs/) to replace Babel as a compiled tool. > Minifying: Removed unnessary code formatting and comments without changing the code's functionality  > Bundled: Resolved the web of dependencies(packages) and merging the files(modules) into optimized bundled for browser, the goal is reducing the number of requests for files when user visit a web page  > Code Splitting: Splitting the application's bundle into smaller chunks required by each entry point ( page URL ). The goal is reducing the initial time for the app - only loading the code required to run that page: - Shared Code between pages - Preloading Code - Dynamic Imports  ### BuildTime vs Runtime ### Rendering on Client/Server -
Nguyen Minh Son revised this gist
Sep 9, 2022 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ # NextJS CheatSheet npx create-next-app seo --use-yarn --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter" 1. Overview Architecture  -
Nguyen Minh Son created this gist
Mar 9, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # NextJS CheatSheet npx create-next-app seo --use-yarn --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"