Git Product home page Git Product logo

nextjs-13-example's Introduction

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

This project uses next/font to automatically optimize and load Inter, a custom Google Font.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Key Ideas

  1. Learn Typescript. The application should be written 100% in Typescript and we want to take advantage of TS tooling. By setting a base URL and paths it will make our imports much easier:
    "baseUrl": ".",
    "paths": {
      "@/components/*": ["components/*"],
      "@/pages/*": ["pages/*"],
      "@/lib/*": ["lib/*"],
      "@/styles/*": ["styles/*"],
      "@/data/*": ["data/*"]
    },
  1. Your 404 page can be "active" and simply redirect you to home.
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';

/*
  simple 404 function to redirect to home
*/
export default function Custom404() {
  const router = useRouter();

  useEffect(() => {
    router.replace('/');
  }, []);

  return null;
}
  1. "Providers" pattern for Theme and Framer Motion. They must run on the client. Context providers are typically rendered near the root of an application to share global concerns, like the current theme. Because context is not supported in Server Components, trying to create a context at the root of your application will cause an error. To fix this, create your context and render its provider inside of a Client Component:
'use client';

import { ThemeProvider } from 'next-themes';
import { LazyMotion, domAnimation } from 'framer-motion';

// see: https://beta.nextjs.org/docs/rendering/server-and-client-components
export const Providers = ({ children }: { children: React.ReactNode }) => {
  return (
    <ThemeProvider attribute='class'>
      <LazyMotion features={domAnimation}>{children}</LazyMotion>
    </ThemeProvider>
  );
};
  1. Use Prettier .prettierrc:
{
  "useTabs": false,
  "printWidth": 100,
  "semi": true,
  "jsxSingleQuote": true,
  "singleQuote": true
}
  1. Metadata for SEO: https://nikolasbarwicki.com/articles/seo-in-next-js-13-with-metadata-api

nextjs-13-example's People

Contributors

dstroot avatar

Stargazers

Ian Halfpenny avatar Jirapan. avatar Sanskar Sahu avatar Adem Arman Yener avatar Arnav Gosain avatar Devolutionary Wizard avatar arifthalhah avatar Demir avatar 衣沾不足惜 avatar Valentin Flageat avatar Andrew Hummel avatar PostPcEra avatar Mohamed Suhail avatar Alex McGarry avatar Afriyan avatar Mohamadjafar Ebrahimi avatar Marton Tasnadi avatar Smith-DoubleMe-Me avatar Sumon Chandra avatar Aleksandra Ivanova avatar Mit Sananikone avatar Shionne Imeris avatar Topten1004 avatar zachi.eth avatar  avatar codedaily avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.