Next.js Counter with useState - Next-js Typing CST Test
Loading…
Next.js Counter with useState — Next-js Code
Simple counter using useState with theme toggle in Next.js.
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
const [isDark, setIsDark] = useState(false);
return (
<div className={isDark ? 'dark-theme' : 'light-theme'} style={{ padding: '2rem' }}>
<h2>Counter: {count}</h2>
<button onClick={() => setCount(count + 1)}>+</button>
<button onClick={() => setCount(count - 1)}>-</button>
<button onClick={() => setCount(0)}>Reset</button>
<button onClick={() => setIsDark(!isDark)}>Switch Theme</button>
<style jsx>{`
.dark-theme { background: #222; color: #eee; min-height: 100vh; }
.light-theme { background: #fff; color: #000; min-height: 100vh; }
button { margin: 0 0.5rem; }
`}</style>
</div>
);
}Next-js Language Guide
Next.js is a powerful React framework for building modern full-stack web applications with features like server-side rendering, static generation, routing, API endpoints, and server components. It emphasizes performance, scalability, and developer experience.
Primary Use Cases
- ▸SEO-optimized websites
- ▸Full-stack React apps with server routes
- ▸E-commerce storefronts
- ▸Dashboards and SaaS apps
- ▸Static or hybrid-rendered marketing sites
Notable Features
- ▸App Router with React Server Components
- ▸File-system routing
- ▸API Routes + serverless functions
- ▸SSR, SSG, ISR, CSR hybrid rendering
- ▸Built-in image optimization
Origin & Creator
Created in 2016 by Guillermo Rauch and maintained by Vercel, designed to simplify server-rendered React applications.
Industrial Note
Next.js excels in enterprise-grade applications, JAMstack workflows, SEO-critical websites, dashboards, and scalable full-stack React platforms.
Quick Explain
- ▸Next.js helps developers build production-ready React applications with routing and rendering handled out of the box.
- ▸It provides hybrid rendering models like SSR, SSG, ISR, and RSC.
- ▸Next.js is optimized for performance, scalability, and full-stack React development.
Core Features
- ▸Server Components by default
- ▸Dynamic and static routing
- ▸Layouts and nested routing
- ▸Next.js API routes for backend logic
- ▸Middleware for edge functions
Learning Path
- ▸Learn React fundamentals
- ▸Understand App Router & routing
- ▸Master Server & Client Components
- ▸Learn Data Fetching & Rendering methods
- ▸Build a real full-stack app with API routes
Practical Examples
- ▸SEO-friendly blog with SSG
- ▸Ecommerce storefront with SSR
- ▸Real-time dashboard using server actions
- ▸Full-stack user auth system
- ▸ISR-powered marketing site
Comparisons
- ▸More full-stack than React alone
- ▸More enterprise-ready than SvelteKit
- ▸More flexible rendering than Angular
- ▸More SEO-friendly than Vue/Nuxt (historically)
- ▸Built for performance at scale
Strengths
- ▸Industry-leading SEO performance
- ▸Best-in-class developer experience
- ▸Full-stack capabilities in a single project
- ▸Highly scalable via Vercel’s edge network
- ▸Deep React ecosystem integration
Limitations
- ▸Learning curve due to multiple rendering strategies
- ▸Server Components may confuse beginners
- ▸Opinionated routing structure
- ▸Performance varies if misconfigured
- ▸Can feel heavy for small apps
When NOT to Use
- ▸Simple static sites (use Astro instead)
- ▸Teams that dislike React
- ▸Apps with extremely custom routing needs
- ▸Lightweight widgets without routing
- ▸Beginner projects sensitive to complexity
Cheat Sheet
- ▸`use client` - enables client component
- ▸`app/page.js` - root route
- ▸`app/layout.js` - shared layout
- ▸`[id]` - dynamic routes
- ▸`route.js` - API route handlers
FAQ
- ▸Is Next.js full-stack?
- ▸Yes, with API routes, server components, and DB access.
- ▸Do I need React to learn Next.js?
- ▸Yes, it's built on React.
- ▸Does Next.js support TypeScript?
- ▸Yes, full support is built in.
- ▸Is Next.js good for SEO?
- ▸Yes, especially with SSR & SSG.
- ▸Is Next.js beginner-friendly?
- ▸Yes, although the App Router adds complexity.
30-Day Skill Plan
- ▸Week 1: React + Next.js basics
- ▸Week 2: Routing, layouts, client components
- ▸Week 3: SSR, SSG, ISR, caching
- ▸Week 4: API routes & databases
- ▸Week 5: Deployments, optimization & middleware
Final Summary
- ▸Next.js is a top-tier full-stack React framework.
- ▸It offers hybrid SSR/SSG/ISR rendering.
- ▸The App Router enables scalable architectures using Server Components.
- ▸Ideal for SEO, dashboards, SaaS, and enterprise apps.
- ▸Backed by Vercel's ecosystem and rapid innovation.
Project Structure
- ▸app/ - routing, pages, layouts
- ▸components/ - UI building blocks
- ▸public/ - static files
- ▸styles/ - global or module CSS
- ▸next.config.js - framework configuration
Monetization
- ▸Build SaaS apps
- ▸Ecommerce stores
- ▸Next.js templates/themes
- ▸Agency services with Next.js
- ▸Internal enterprise portals
Productivity Tips
- ▸Use Server Components for heavy logic
- ▸Use layouts for code reuse
- ▸Leverage built-in caching
- ▸Use Turbo tasks for faster builds
- ▸Integrate with Prisma for full-stack dev
Basic Concepts
- ▸Server vs Client components
- ▸Layouts and nested routes
- ▸Rendering models (SSR, SSG, ISR)
- ▸API routes and server actions
- ▸Image and font optimization