Kick off your project with this boilerplate.
git clone
cd
yarn install
yarn run dev
your site is now running at http://localhost:3000
A quick look at the directories you'll see in this project.
.
βββ pages #
βββ public #
βββ styles #
βββ api #
βββ components #
βββ context # (alternatively `store`)
βββ hooks # Custom hooks
βββ utils #
βββ libs #
βββ cypress # Automated tests
βββ README.md #
βββ ...
Each page is associated with a route based on its file name.
.
βββ ...
βββ pages #
β βββ api # API endpoint
β βββ _app.tsx # App component to initialize pages
β βββ _document.tsx # Custom document to augment application's <html> and <body> tags
β βββ ...
βββ ...
Next.js can serve static files, like images, under a folder called public in the root directory.
.
βββ ...
βββ public #
β βββ favicons #
β βββ ...
βββ ...
Css, theme configuration files are placed into this folder.
.
βββ ...
βββ styles #
β βββ theme.tsx #
β βββ ...
βββ ...
Api call related functions.
Components are independent and reusable bits of code.
.
βββ ...
βββ components #
β βββ icons #
β βββ atoms #
β βββ molecules #
β βββ organisms #
β βββ templates #
βββ ...
Context provides a way to pass data through the component tree without having to pass props down manually at every level. (just like redux)
.
βββ ...
βββ context #
β βββ auth #
β βββ ...
βββ ...
Custom hook allows you to extract some components logic into a reusable function that starts with use and that call can other hooks.
.
βββ ...
βββ hooks #
β βββ useScript.tsx #
β βββ ...
βββ ...
Small snippets you can use throughout the application. Short and specific functions and constants used throughout application.
Libraries you can use throughout the application. A library is a JavaScript file that contains a bunch of functions, and those functions accomplish some specific purpose.
.
βββ ...
βββ libs #
β βββ gtm.ts #
β βββ ...
βββ ...
Automated tests with cypress.
.
βββ ...
βββ cypess #
β βββ fixtures # Fixed data sets
β βββ integration # End-to-end, integration tests (alternatively `e2e`)
β βββ plugins #
β βββ support #
βββ ...
-
Extensions: Use .tsx extension for React components.
-
Filename: Use PascalCase for filenames. E.g., ReservationCard.tsx.
-
Reference Naming: Use PascalCase for React components and camelCase for their instances.
// bad import reservationCard from './ReservationCard'; // good import ReservationCard from './ReservationCard'; // bad const ReservationItem = <ReservationCard />; // good const reservationItem = <ReservationCard />;
-
Component Naming: Use the filename as the component name. For example, ReservationCard.tsx should have a reference name of ReservationCard. However, for root components of a directory, use index.tsx as the filename and use the directory name as the component name:
// bad import Footer from './Footer/Footer'; // bad import Footer from './Footer/index'; // good import Footer from './Footer';
Always use camelCase for others.
- scripts
- folders
- variables
- functions
- Framework: Next.js
- State Management: React Query, Context API
- Styling: Chakra-ui, Emotion
- Forms: React Hook Form
- Testing: Cypress