Back to articles
Next.js Has a Free API — Here's How to Build Full-Stack React Apps with Server Components

Next.js Has a Free API — Here's How to Build Full-Stack React Apps with Server Components

via Dev.to ReactAlex Spinov

Next.js 14+ brings React Server Components, Server Actions, and the App Router — enabling full-stack React apps with minimal client JavaScript. Getting Started npx create-next-app@latest my-app --typescript --tailwind --app cd my-app npm run dev Server Components (Default) // app/posts/page.tsx — runs on server, zero client JS async function getPosts () { const res = await fetch ( " https://api.example.com/posts " , { next : { revalidate : 60 } }); return res . json (); } export default async function PostsPage () { const posts = await getPosts (); return ( < div > < h1 > Blog Posts </ h1 > { posts . map ( post => ( < article key = { post . id } > < h2 > { post . title } </ h2 > < p > { post . excerpt } </ p > </ article > )) } </ div > ); } Client Components " use client " ; import { useState } from " react " ; export function Counter () { const [ count , setCount ] = useState ( 0 ); return ( < button onClick = { () => setCount ( c => c + 1 ) } > Count: { count } </ button > ); } Serv

Continue reading on Dev.to React

Opens in a new tab

Read Full Article
2 views

Related Articles