Saved Offline Revision

Saved Notes & Cards

Quick access to your saved code snippets, revision cards, and tutorial notes.

Saved Flashcards (3)

React Hooks

How do you correctly update state based on previous state in React?

Use a functional updater: `setCount(prev => prev + 1)`. This guarantees stale closure prevention during batch updates.

const [count, setCount] = useState(0);
// Correct way:
setCount(prev => prev + 1);
Next.js Route Handler

Where do you define REST API endpoints in Next.js App Router?

Inside `app/api/[route]/route.js` by exporting named async functions `export async function GET(request) {}`

// app/api/hello/route.js
import { NextResponse } from 'next/server';
export async function GET() {
  return NextResponse.json({ message: 'Hello!' });
}
Mongoose Querying

How to fetch only `title` and `author` while excluding `_id` in Mongoose?

Use `.select('title author -_id')` or `.select({ title: 1, author: 1, _id: 0 })`

const result = await Article.find().select('title author -_id');

Saved Tutorials (2)

reactjs

1. Introduction to React & JSX

What is React, Virtual DOM, and how JSX transforms HTML inside JavaScript.

reactjs

2. Components & Props

Building modular UI components and passing read-only data via props.