Steps to create a nextJS application
Step 1: Create a nextJS app
Run the following command and configure as shown in figure below to setup nextJS app.
npx create-next-app demo
Step 2: Start nextJS demo app
navigate to the created folder and run the application using following commands.
cd demo
If in case any error in creation check the dependencies and scripts below if any mismatch incase. use latest version if not update to latest one. use following command to update nextJS version.
npm install next@latest
Step 3: Access your application
For accessing your application visit http://localhost:3000
Detecting server vs client in NextJS application
Next.js, a popular React framework, helps you to build powerful web applications with ease. However, managing server-side and client-side execution can pose unique challenges. In this article, we’ll explore techniques for detecting server or client execution in Next.js applications.
Table of Content
- What is Server Side Rendering?
- What is Client Side Rendering?
- Detecting server vs client-side rendering
- 1: Using typeof window
- 2: Using process.browser
- 3: Using a custom flag
- 4: Using req object in getServerSideProps
- 5: Using window object inside useEffect