Learn and Teach Coding
Practical coding examples and tutorials for React, Next.js, JavaScript, TypeScript, and .NET.
⌘K
Featured Examples
.NETIntermediate
.NET Repository Pattern
Implement the repository pattern with Entity Framework Core.
View exampleNBeginner
Next.js API Route CRUD
Create a full CRUD API using Next.js API Routes and Prisma.
View exampleJSIntermediate
Debounced Search in JavaScript
Implement a debounced search input with vanilla JavaScript.
View exampleBeginner
React Login Form Validation
Build a login form with validation using React Hook Form and Zod.
View exampleBrowse Topics
Find examples and tutorials by technology.
Try an Example
Every example is a real, working component. Press start.
00:00:00.00
React Stopwatch Example
export default function Stopwatch() {
const [ms, setMs] = useState(0);
const [running, setRunning] = useState(false);
const startedAt = useRef(0);
useEffect(() => {
if (!running) return;
// Anchor to a fixed origin so pausing/resuming stays accurate.
startedAt.current = performance.now() - ms;
let frame = 0;
const tick = () => {
setMs(performance.now() - startedAt.current);
frame = requestAnimationFrame(tick);
};
frame = requestAnimationFrame(tick);
return () => cancelAnimationFrame(frame);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [running]);Latest Tutorials
Build Authentication in Next.js with Credentials and JWTNext.js · 12 min readMay 24, 2024IntermediateUnderstanding useEffect in React with Practical ExamplesReact · 9 min readMay 20, 2024BeginnerReact Form State Management with React Hook FormReact · 10 min readMay 18, 2024IntermediateEntity Framework Core Relationships Explained.NET · 11 min readMay 15, 2024Intermediate