Quick-reference guide for React, Next.js, APIs, CLI/Git, TypeScript, and Framer Motion. Each section includes syntax, one-line descriptions, and Tips & Gotchas like MDN notes. Use Ctrl+F to search.
Description: Creates a state variable in a component and provides a setter to update it, triggering a re-render.
const [count, setCount] = useState(0);
setCount(count + 1);
Description: Runs code after render. Useful for data fetching, timers, or interacting with the DOM.
useEffect(() => {
console.log("Runs once on mount");
}, []);
Description: Return a cleanup function to remove event listeners, clear timers, or reset resources.
useEffect(() => {
const id = setInterval(() => console.log("tick"), 1000);
return () => clearInterval(id);
}, []);
Description: Render arrays with map(). Always include a unique key.
{items.map((item) => <li key={item.id}>{item.name}</li>)}
setCount(prev => prev + 1).[] = run once (on mount).Description: File-based routing — file and folder names define routes.
# Pages router
pages/index.js → /
pages/about.js → /about
# App router
app/page.tsx → /
app/about/page.tsx → /about
Description: Store secrets/config in .env.local. NEXT_PUBLIC_ variables are exposed client-side.
# .env.local
NEXT_PUBLIC_API_URL=https://api.example.com
Description: In the App Router, server components can fetch data directly without useEffect.
export default async function Page() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return <pre>{JSON.stringify(data)}</pre>;
}
Description: Retrieve data from the server.
const res = await fetch("/api/items");
const data = await res.json();
Description: Send new data to the server.
await fetch("/api/items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "New item" }),
});
Description: Delete a resource by ID.
await fetch(`/api/items/${id}`, { method: "DELETE" });
res.ok before parsing JSON.Description: Manage code with Git: check status, stage, commit, and push changes.
git status
git add .
git commit -m "message"
git push origin main
git pull
Description: Create and run a new project.
npx create-next-app@latest myapp
npm run dev
Description: Handy development utilities.
npx kill-port 3000
npx prettier --write .
git checkout -b feature/navbar.git pull --rebase keeps history clean.Description: Explicitly declare variable types for safety and autocompletion.
let age: number = 25;
let name: string = "Alex";
let tags: string[] = ["react", "ts"];
Description: Define parameter and return types.
function add(a: number, b: number): number {
return a + b;
}
Description: Define prop types with type or interface.
type Props = { title: string; count?: number };
function Header({ title, count }: Props) {}
? for optional props.interface for extendable object shapes.Description: Animate between initial and target states.
import { motion } from "framer-motion";
<motion.div initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.5 }}>
Hello
</motion.div>
Description: Apply animations on hover.
<motion.button whileHover={{ scale: 1.1 }}>
Click
</motion.button>
Description: Named sets of animation states for reuse.
const box = { hidden: { x: -100 }, visible: { x: 0 } };
<motion.div variants={box} initial="hidden" animate="visible" />
Description: Quick plan to connect a Next.js app to a free API.
https://api.quotable.io/random).npx create-next-app my-api-test.export default async function Page() {
const res = await fetch("https://api.quotable.io/random");
const data = await res.json();
return <p>{data.content} — {data.author}</p>;
}
useState/useEffect.