JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsreact

react

React components, hooks, patterns, and best practices

Explore 20 react topics to deepen your understanding

Your Progress

0 of 18 completed

0%

18 Questions

mid Level
1
Explain the useState and useEffect hooks and their common patterns.
mid
hooks
useState manages local state in functional components, returning a value and setter function. useEffect handles side effects (data fetching, subscriptions, DOM manipulation) and runs after render. The dependency array controls when effects re-run.
2
What is React Context and when should you use it?
mid
context
Context provides a way to pass data through the component tree without prop drilling. Use it for global data like themes, authentication, or locale. For frequently changing data or complex state logic, consider state management libraries instead.
3
What are custom hooks and how do you create them?
mid
hooks
Custom hooks are JavaScript functions starting with 'use' that encapsulate reusable stateful logic. They can use other hooks and share logic between components without duplicating code or adding components to the tree.
4
What is useRef and when should you use it?
mid
hooks
useRef creates a mutable reference that persists across renders without causing re-renders when changed. Use it for accessing DOM elements, storing mutable values that don't need to trigger updates, and keeping references to timers or previous values.
5
What is the difference between controlled and uncontrolled components in React forms?
mid
forms
Controlled components have their form data managed by React state - the input value is always driven by state. Uncontrolled components let the DOM handle form data using refs to access values when needed. Controlled components are recommended for most cases.
6
How does React Router work and what are its key features?
mid
routing
React Router provides client-side routing for React applications, enabling navigation without page reloads. It uses components like BrowserRouter, Routes, Route, and Link, with hooks like useNavigate and useParams for programmatic navigation and accessing route parameters.
7
How do you ensure accessibility (a11y) in React applications?
mid
accessibility
Ensure accessibility by using semantic HTML elements, proper ARIA attributes (aria-label, role), managing focus for dynamic content, supporting keyboard navigation, using htmlFor with labels, and testing with tools like eslint-plugin-jsx-a11y and screen readers.
8
How do you integrate UI component libraries with React and when should you use them?
mid
libraries
UI libraries like Material-UI, Chakra UI, and Radix provide pre-built, accessible components. Integrate them by installing the package, wrapping your app with a ThemeProvider, and importing components. Use them for rapid development and consistent design; build custom when you need unique designs or minimal bundle size.
9
How do useSelector and useDispatch work in React-Redux?
mid
state-management
useSelector reads data from the Redux store by accepting a selector function that receives the entire state and returns the needed slice. useDispatch returns the store's dispatch function to send actions. Together they replace the older connect() HOC pattern with a simpler hooks-based API.
10
How would you implement a useLocalStorage custom hook?
mid
custom-hooks
A useLocalStorage hook syncs React state with the browser's localStorage, providing a useState-like API that automatically persists values across page reloads. It handles JSON serialization, error recovery, SSR safety, and can synchronize across browser tabs via the storage event.
11
How would you implement a useFetch custom hook?
mid
custom-hooks
A useFetch hook encapsulates data fetching logic with loading, error, and data states. It uses AbortController to handle cleanup and race conditions when the URL changes or the component unmounts, and can support refetch and basic caching.
12
What are the differences between CSR, SSR, and SSG in React applications?
mid
rendering
CSR renders entirely in the browser, SSR generates HTML on each request server-side, and SSG pre-builds HTML at build time. Each has different tradeoffs for performance, SEO, and data freshness.
13
What are React Fragments and when should you use them?
mid
fragments
React Fragments let you group multiple elements without adding an extra DOM node. Use the <Fragment> syntax when you need to pass a key prop, or the shorter <>...</> syntax when you don't.
14
How do React component lifecycle methods map to hooks in functional components?
mid
lifecycle
useEffect with an empty dependency array replaces componentDidMount, useEffect with dependencies replaces componentDidUpdate, and the useEffect cleanup function replaces componentWillUnmount. However, hooks represent a different mental model focused on synchronizing with external systems rather than responding to lifecycle events.
15
When should you use Context API vs Redux for state management?
mid
state-management
Use Context API for simple, low-frequency state (theme, auth, locale) shared across components. Use Redux (or Redux Toolkit) for complex, frequently-updated state that benefits from middleware, selective subscriptions, time-travel debugging, and predictable update patterns.
16
Build an OTP (One-Time Password) input component in React that auto-advances focus between fields, supports paste, and handles backspace navigation.
mid
machine-coding
An OTP input renders N separate single-character inputs with automatic focus management — advancing on input, reversing on backspace, and handling clipboard paste to distribute digits across all fields.
17
Build an autocomplete/typeahead search component in React that fetches suggestions from an API with debouncing, keyboard navigation, and highlighted matching text.
mid
machine-coding
An autocomplete component debounces user input, fetches matching suggestions from an API, renders a dropdown with keyboard navigation (arrow keys + Enter), highlights the matched portion of each suggestion, and handles edge cases like race conditions and empty states.
18
Build an infinite scroll component in React using Intersection Observer that loads more items as the user scrolls, with loading states and race condition handling.
mid
machine-coding
Infinite scroll uses Intersection Observer to detect when a sentinel element near the bottom of the list enters the viewport, triggering a fetch for the next page of data. A ref-based approach with proper cleanup prevents race conditions and duplicate requests.