JavaScriptReactAngularVueSvelteCSSHTMLTypeScript

React 编码面试问题

90+ 最重要的 React 编码面试问题:从状态管理到钩子以及组件设计。
由前面试官解答
测试场景
在浏览器中编码

题目列表

React 面试指南涵盖核心概念和特定于面试的 React 提示的全面 React 面试指南
0/12 指南
指南
  • Counter热身问题Build a simple counter that increments whenever a button is clicked
    可用的框架
  • useBooleanImplement a hook that manages a boolean state, with additional convenience utility methods
    语言
  • useCounterImplement a hook that manages a counter state, with some additional convenience utility methods
    语言
  • AccordionBuild an accordion component that a displays a list of vertically stacked sections with each containing a title and content snippet
    可用的框架
  • Contact FormBuild a contact form which submits user feedback and contact details to a back end API
    可用的框架
  • Holy GrailBuild the famous holy grail layout consisting of a header, 3 columns, and a footer
    可用的框架
  • Progress BarsBuild a list of progress bars that fill up gradually when they are added to the page
    可用的框架
  • useClickAnywhereImplement a hook that handles click events anywhere on the document
    语言
  • useCounter IIImplement an optimized version of the useCounter hook
    语言
  • useCycleImplement a hook that cycles through a sequence of values
    语言
  • Mortgage CalculatorBuild a calculator that computes the monthly mortgage for a loan
    可用的框架
  • TabsBuild a tabs component that displays a list of tab elements and one associated panel of content at a time
    可用的框架
  • useArrayImplement a hook that manages an array of items
    语言
  • useDebounceImplement a hook that debounces a value
    语言
  • useSetImplement a hook that manages a JavaScript set
    语言
  • useTimeoutImplement a hook that invokes a callback function after a specified delay
    语言
  • useWindowSizeImplement a hook that returns the current height and width of the window
    语言
  • Data TableBuild a users data table with pagination features
    可用的框架
  • Dice RollerBuild a dice roller app that simulates the results of rolling 6-sided dice
    可用的框架
  • File ExplorerBuild a file explorer component to navigate files and directories in a tree-like hierarchical viewer
    可用的框架
  • Like ButtonBuild a Like button that changes appearance based on the states
    可用的框架
  • Modal DialogBuild a reusable modal dialog component that can be opened and closed
    可用的框架
  • Star RatingBuild a star rating component that shows a row of star icons for users to select the number of filled stars corresponding to the rating
    可用的框架
  • Todo ListBuild a Todo list that lets users add new tasks and delete existing tasks
    可用的框架
  • Traffic LightBuild a traffic light where the lights switch from green to yellow to red after predetermined intervals and loop indefinitely
    可用的框架
  • useInputControlImplement a hook that manages a controlled input value and tracks its dirty & touched state
    语言
  • useMediaQueryImplement a hook that subscribes and responds to media query changes (e.g. screen size, resolution, orientation, etc.)
    语言
  • useMediatedStateImplement a hook that is similar to useState, but supports a mediation process
    语言
  • useQueryImplement a hook that manages a promise resolution
    语言
  • Digital ClockBuild a 7-segment digital clock that shows the current time
    可用的框架
  • Tic-tac-toeBuild a tic-tac-toe game that is playable by two players
    可用的框架
  • Image CarouselBuild an image carousel that displays a sequence of images
    可用的框架
  • Job BoardBuild a job board that displays the latest job postings from Hacker News
    可用的框架
  • StopwatchBuild a stopwatch widget that can measure how much time has passed
    可用的框架
  • Transfer ListBuild a component that allows transferring of items between two lists
    可用的框架
  • Nested CheckboxesBuild a nested checkboxes component with parent-child selection logic
    可用的框架
  • Flight Booker高级Build a component that books a flight for specified dates
    可用的框架
  • Generate Table高级Generate a table of numbers given the rows and columns
    可用的框架
  • Progress Bar高级Build a progress bar component that shows the percentage completion of an operation
    可用的框架
  • Temperature Converter高级Build a temperature converter widget that converts temperature values between Celsius and Fahrenheit
    可用的框架
  • useBoolean II高级Implement an optimized version of the useBoolean hook
    语言
  • useDefault高级Implement a hook that returns the default value when state is null or undefined
    语言
  • useEffectOnce高级Implement a hook that runs an effect only once
    语言
  • useFocus高级Implement a hook that enables programmatic focusing of an element
    语言
  • usePrevious高级Implement a hook that returns the previous value of a state
    语言
  • useStateWithReset高级Implement a hook that's similar to useState but with an additional reset function that resets the state to its initial value
    语言
  • useToggle高级Implement a hook that manages a boolean toggle state
    语言
  • Tweet高级Build a component that resembles a Tweet from Twitter
    可用的框架
  • useBreakpoint高级Implement a hook that returns the current breakpoint name based on the current window width
    语言
  • useClickOutside高级Implement a hook that detects clicks outside of a specified element
    语言
  • useCountdown高级Implement a hook that manages a countdown
    语言
  • useEventListener高级Implement a hook that subscribes to browser events
    语言
  • useHover高级Implement a hook that tracks whether an element is being hovered
    语言
  • useInterval高级Implement a hook that creates an interval that invokes a callback function at a specified delay
    语言
  • useKeyPress高级Implement a hook that subscribes to keyboard events
    语言
  • useMap高级Implement a hook that manages a JavaScript map
    语言
  • useObject高级Implement a hook that manages an object value
    语言
  • useStep高级Implement a hook that manages a step counter for a multi-step process
    语言
  • useThrottle高级Implement a hook that throttles a value
    语言
  • Accordion II高级Build an accessible accordion component that has the right ARIA roles, states, and properties
    可用的框架
  • Accordion III高级Build a fully accessible accordion component that has keyboard support according to ARIA specifications
    可用的框架
  • Analog Clock高级Build an analog clock where the hands update and move like a real clock
    可用的框架
  • Data Table II高级Build a users data table with sorting features
    可用的框架
  • File Explorer II高级Build a semi-accessible file explorer component that has the right ARIA roles, states, and properties
    可用的框架
  • File Explorer III高级Build a file explorer component using a flat DOM structure
    可用的框架
  • Grid Lights高级Build a grid of lights where the lights deactivate in the reverse order they were activated
    可用的框架
  • Modal Dialog II高级Build a semi-accessible modal dialog component that has the right ARIA roles, states, and properties
    可用的框架
  • Modal Dialog III高级Build a moderately-accessible modal dialog component that supports common ways to close the dialog
    可用的框架
  • Progress Bars II高级Build a list of progress bars that fill up gradually in sequence, one at a time
    可用的框架
  • Tabs II高级Build a semi-accessible tabs component that has the right ARIA roles, states, and properties
    可用的框架
  • Tabs III高级Build a fully accessible tabs component that has keyboard support according to ARIA specifications
    可用的框架
  • useIdle高级Implement a hook that detects user inactivity
    语言
  • Progress Bars III高级Build a list of progress bars that fill up gradually concurrently, up to a limit of 3
    可用的框架
  • Birth Year Histogram高级Build a widget that fetches birth year data from an API and plot it on a histogram
    可用的框架
  • Connect Four高级Build a game for two players who take turns to drop colored discs from the top into a vertically suspended board/grid
    可用的框架
  • Image Carousel II高级Build an image carousel that smoothly transitions between images
    可用的框架
  • Pixel Art高级Build a pixel art drawing tool where users can paint pixels with selected colors
    可用的框架
  • Undoable Counter高级Build a counter with a history of the values and ability to undo/redo actions
    可用的框架
  • Users Database高级Build a UI to filter, create, update, and delete users
    可用的框架
  • Whack-A-Mole高级Build a popular arcade game where players attempt to hit moles as they pop up from holes in a board
    可用的框架
  • Memory Game高级Build a memory game where the player needs to match pairs of cards
    可用的框架
  • Auth Code Input高级Build an auth code input component that allows users to enter a 6-digit authorization code
    可用的框架
  • Progress Bars IV高级Build a list of progress bars that fill up gradually concurrently, up to a limit of 3 and allows for pausing and resuming
    可用的框架
  • Data Table III高级Build a generalized data table with pagination and sorting features
    可用的框架
  • Modal Dialog IV高级Build a fully-accessible modal dialog component that supports all required keyboard interactions
    可用的框架
  • Data Table IV高级Build a generalized data table with pagination, sorting and filtering features
    可用的框架
  • Image Carousel III高级Build an image carousel that smoothly transitions between images that has a minimal DOM footprint
    可用的框架
  • Selectable Cells高级Build an interface where users can drag to select multiple cells within a grid
    可用的框架
  • Tic-tac-toe II高级Build an N x N tic-tac-toe game that requires M consecutive marks to win
    可用的框架
  • Transfer List II高级Build a component that allows transferring of items between two lists, bulk selection/unselection of items, and adding of new items
    可用的框架
  • Wordle高级Build Wordle, the word-guessing game that took the world by storm
    可用的框架

React Coding Interview Questions and Answers

Preparing for a React coding interview? Our comprehensive list of React coding interview questions is designed to help you master essential React concepts, techniques, and patterns. From building interactive components and managing state to handling routing and optimizing performance, our expertly crafted questions cover everything you need to succeed.

Each question comes with example solutions, detailed explanations, and best practices to ensure a thorough understanding of React development. Whether you're new to React or aiming to refine your skills, this resource provides a structured approach to acing your interview.

Practice in a Realistic Environment

Our platform includes an in-browser coding workspace that allows you to code directly in your browser without any setup. This feature simulates a real interview environment by:

  • Providing real-time feedback: Instantly test your code against automated test cases to validate accuracy and identify potential issues.
  • Enhancing iterative learning: Refine your code as you receive feedback and incorporate best practices into your solutions.
  • Boosting confidence: Gain hands-on experience with real-world React challenges, preparing you for the technical aspects of interviews.

All solutions are crafted by experienced former senior / staff engineers, ensuring high-quality content that mirrors industry expectations.

Categories of React Coding Interview Questions

Our questions are divided into two key categories, allowing you to focus on specific aspects of React development:

React User Interface Interview Questions

Building dynamic, responsive, and user-friendly interfaces is at the heart of React development. This category focuses on:

  • Creating components and widgets: Practice constructing reusable UI elements such as buttons, modals, and dropdowns.
  • Dynamic interactions: Solve challenges like creating sortable tables, dynamic forms, and interactive to-do lists.
  • Responsive design: Learn to design components that adapt seamlessly across devices using React.

Example question: How would you build a sortable table component in React?

Solution and approach:

  1. Use state to store the current sort order and column.
  2. Create a function to toggle the sort order and sort data dynamically.
  3. Render sorted rows in the table based on the selected column.
function SortableTable({ data, columns }) {
const [sortColumn, setSortColumn] = React.useState(null);
const [sortOrder, setSortOrder] = React.useState('asc');
const handleSort = (column) => {
const order = sortColumn === column && sortOrder === 'asc' ? 'desc' : 'asc';
setSortColumn(column);
setSortOrder(order);
};
const sortedData = React.useMemo(() => {
if (!sortColumn) return data;
return [...data].sort((a, b) => {
if (a[sortColumn] < b[sortColumn]) return sortOrder === 'asc' ? -1 : 1;
if (a[sortColumn] > b[sortColumn]) return sortOrder === 'asc' ? 1 : -1;
return 0;
});
}, [data, sortColumn, sortOrder]);
return (
<table>
<thead>
<tr>
{columns.map((col) => (
<th key={col} onClick={() => handleSort(col)}>
{col}
</th>
))}
</tr>
</thead>
<tbody>
{sortedData.map((row, index) => (
<tr key={index}>
{columns.map((col) => (
<td key={col}>{row[col]}</td>
))}
</tr>
))}
</tbody>
</table>
);
}

React Hooks and State Management Interview Questions

React Hooks and effective state management are critical for creating scalable and maintainable applications. In this category, you'll encounter:

  • Custom hooks: Learn to encapsulate reusable logic, such as fetching data or managing form inputs.
  • State management with useReducer: Master managing complex state transitions in larger components or applications.
  • Performance optimization: Solve challenges related to minimizing re-renders using hooks like useMemo and React.memo.

Example question: How would you implement a custom hook for fetching data?

Solution and approach:

  1. Use useState to manage data and loading states.
  2. Use useEffect to fetch data from the provided API endpoint.
  3. Handle error states gracefully and provide a reusable interface.
function useFetch(url) {
const [data, setData] = React.useState(null);
const [loading, setLoading] = React.useState(true);
const [error, setError] = React.useState(null);
React.useEffect(() => {
let isMounted = true;
setLoading(true);
fetch(url)
.then((response) => response.json())
.then((data) => {
if (isMounted) setData(data);
})
.catch((err) => {
if (isMounted) setError(err.message);
})
.finally(() => {
if (isMounted) setLoading(false);
});
return () => {
isMounted = false;
};
}, [url]);
return { data, loading, error };
}

Why Choose Our React Coding Interview Questions?

  1. Comprehensive coverage: We cover everything from basic React concepts to advanced patterns, ensuring you're fully prepared for any interview scenario.
  2. Practical, hands-on learning: Solve real-world React challenges in a coding environment designed to mimic interview conditions.
  3. Expert-crafted solutions: Learn from high-quality explanations and best practices written by experienced engineers with deep industry knowledge.
  4. Immediate feedback: Validate your code with automated test cases to identify and correct mistakes instantly, accelerating your learning process.

How These Questions Prepare You for Success

By practicing with our React coding interview questions, you'll:

  • Master core concepts: Develop a deep understanding of React fundamentals, hooks, and state management.
  • Enhance problem-solving skills: Tackle challenges that require critical thinking and systematic approaches to solving real-world problems.
  • Build confidence: Familiarize yourself with common React interview patterns, reducing anxiety and improving performance during interviews.
  • Apply best practices: Learn industry standards for structuring components, managing state, and optimizing application performance.

Excel in Your React Coding Interviews

Our React coding interview resource goes beyond preparation. It equips you with the skills and confidence to excel in any interview scenario, whether you're a front-end engineer, a full-stack developer, or exploring new career opportunities in React development. Dive into hands-on practice, refine your solutions with expert guidance, and build the expertise needed to stand out as a React developer.

Related lists

Check out other lists of questions below if you're looking for something more specific: