
React Hooks
useState, useEffect, useContext, useRef, useCallback, useMemo, custom hooks
1What is the useState hook in React?
What is the useState hook in React?
Answer
useState is a React hook that manages local state in a functional component. Unlike regular JavaScript variables that are reset on every render, useState preserves the state value between successive renders. This hook returns an array containing the current state value and a function to update it, automatically triggering a component re-render when the state changes.
2What is the correct syntax to declare state with useState?
What is the correct syntax to declare state with useState?
Answer
The correct syntax uses array destructuring to extract the state value and its update function. By convention, the update function is prefixed with 'set' followed by the state variable name in camelCase. This convention improves code readability and is widely adopted in the React community. The order of elements in the array returned by useState is always the same: current value first, update function second.
3What happens when calling a state update function?
What happens when calling a state update function?
Answer
When a state update function is called, React schedules a new component render with the new state value. The update is not immediate but asynchronous, meaning the state value is not modified instantly after the call. React batches multiple state updates to optimize performance and avoid triggering unnecessary renders. This batching strategy significantly improves application performance.
How to update state based on its previous value?
Can multiple useState hooks be used in the same component?
+19 interview questions
Other React / Next.js interview topics
JavaScript Essentials
React Fundamentals
Component Lifecycle
React Router
State Management with Context
Forms & Controlled Components
Data Fetching & API
React Query (TanStack Query)
Styling & CSS-in-JS
Next.js Fundamentals
TypeScript with React
Next.js Data Fetching
Next.js Server Actions
Next.js Routing & Navigation
Next.js API Routes
Next.js Metadata & SEO
Next.js Middleware & Auth
React Testing
Zustand State Management
React Performance Optimization
Error Boundaries & Error Handling
Advanced React Patterns
Next.js Advanced Features
Next.js Deployment & Production
Architecture & Design Patterns
React Server Components
Next.js Internationalization
React Security & Best Practices
Master React / Next.js for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free