JavaScriptReactAngularVueSvelteCSSHTMLTypeScript

React编码面试问题

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

题目列表

React 面试指南一份全面的 React 面试指南,涵盖核心概念和特定于面试的 React 技巧
0/12指南
指南
  • Counter热身问题Build a simple counter that increments whenever a button is clicked
    可用的框架
  • useBoolean实现一个管理布尔状态的 Hook,并提供额外的便捷实用方法
    语言
  • useCounter实现一个管理计数器状态的 Hook,并提供一些额外的便捷实用方法
    语言
  • 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
    可用的框架
  • useClickAnywhere实现一个处理文档任何位置的点击事件的 Hook
    语言
  • useCounter II实现 useCounter hook 的优化版本
    语言
  • useCycle实现一个循环遍历一系列值的 hook
    语言
  • 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
    可用的框架
  • useArray实现一个管理项目数组的 Hook
    语言
  • useDebounce实现一个对值进行防抖的 Hook
    语言
  • useSet实现一个管理 JavaScript Set 的 Hook
    语言
  • useTimeout实现一个在指定延迟后调用回调函数的 Hook
    语言
  • useWindowSize实现一个返回窗口当前高度和宽度的 Hook
    语言
  • 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
    可用的框架
  • useInputControl实现一个管理受控输入值并跟踪其脏和已触及状态的 hook
    语言
  • useMediaQuery实现一个订阅并响应媒体查询变化的 Hook(例如屏幕大小、分辨率、方向等)
    语言
  • useMediatedState实现一个类似于 useState 的 hook,但支持一个中介过程
    语言
  • useQuery实现一个管理 promise 结果的 hook
    语言
  • 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高级实现 useBoolean hook 的优化版本
    语言
  • useDefault高级实现一个在状态为 null 或 undefined 时返回默认值的 hook
    语言
  • useEffectOnce高级实现一个只运行一次 effect 的 hook
    语言
  • useFocus高级实现一个可以对元素进行程序化聚焦的 Hook
    语言
  • usePrevious高级实现一个返回状态前一个值的 Hook
    语言
  • useStateWithReset高级实现一个类似于 useState 的 hook,但它有一个额外的 reset 函数,可以将状态重置为其初始值
    语言
  • useToggle高级实现一个管理布尔切换状态的 Hook
    语言
  • Tweet高级Build a component that resembles a Tweet from Twitter
    可用的框架
  • useBreakpoint高级实现一个基于当前窗口宽度返回当前断点名称的 Hook
    语言
  • useClickOutside高级实现一个检测指定元素外部点击的 Hook
    语言
  • useCountdown高级实现一个管理倒计时的 Hook
    语言
  • useEventListener高级实现一个订阅浏览器事件的 Hook
    语言
  • useHover高级实现一个跟踪元素是否被悬停的 Hook
    语言
  • useInterval高级实现一个创建间隔的 hook,该间隔在指定的延迟后调用回调函数
    语言
  • useKeyPress高级实现一个订阅键盘事件的 Hook
    语言
  • useMap高级实现一个管理 JavaScript map 的 Hook
    语言
  • useObject高级实现一个管理对象值的 Hook
    语言
  • useStep高级实现一个管理多步骤流程的步骤计数器的 hook
    语言
  • useThrottle高级实现一个节流值的 Hook
    语言
  • 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高级实现一个检测用户不活动状态的 Hook
    语言
  • 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 编码面试问题和答案

准备 React 编码面试?我们全面的 React 编码面试问题列表旨在帮助您掌握基本的 React 概念、技术和模式。从构建交互式组件和管理状态到处理路由和优化性能,我们精心设计的问题涵盖了您取得成功所需的一切。

每个问题都附带示例解决方案、详细说明和最佳实践,以确保彻底理解 React 开发。无论您是 React 新手还是旨在提升技能,此资源都提供了一种结构化的方法来通过面试。

在真实环境中练习

我们的平台包含一个浏览器内编码工作区,允许您直接在浏览器中编码,无需任何设置。此功能模拟真实的面试环境,通过:

  • 提供实时反馈:立即根据自动化测试用例测试您的代码,以验证准确性并识别潜在问题。
  • 增强迭代学习:在您收到反馈并结合最佳实践到您的解决方案中时,完善您的代码。
  • 增强信心:获得真实的 React 挑战的实践经验,为您准备面试的技术方面。

所有解决方案均由经验丰富的资深/骨干工程师精心打造,确保高质量的内容,与行业期望相符。

React 编码面试问题的类别

我们的问题分为两个关键类别,让您可以专注于 React 开发的特定方面:

React 用户界面面试问题

构建动态、响应式和用户友好的界面是 React 开发的核心。此类别侧重于:

  • 创建组件和小部件:练习构建可重用的 UI 元素,例如按钮、模态框和下拉列表。
  • 动态交互:解决创建可排序表格、动态表单和交互式待办事项列表等挑战。
  • 响应式设计:学习使用 React 设计可在各种设备上无缝适配的组件。

示例问题:您将如何在 React 中构建一个可排序的表格组件?

解决方案和方法:

  1. 使用状态存储当前的排序顺序和列。
  2. 创建一个函数来切换排序顺序并动态排序数据。
  3. 根据所选列在表格中呈现排序后的行。
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 和状态管理面试问题

React Hooks 和有效的状态管理对于创建可扩展和可维护的应用程序至关重要。在此类别中,您将遇到:

  • 自定义 hooks:学习封装可重用的逻辑,例如获取数据或管理表单输入。
  • 使用 useReducer 进行状态管理:掌握在更大的组件或应用程序中管理复杂的状态转换。
  • 性能优化:解决与使用 useMemoReact.memo 等 hooks 最小化重新渲染相关的挑战。

示例问题:您将如何实现一个用于获取数据的自定义 hook?

解决方案和方法:

  1. 使用useState管理数据和加载状态。
  2. 使用useEffect从提供的API端点获取数据。
  3. 优雅地处理错误状态并提供可重用的接口。
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 };
}

为什么选择我们的React编码面试问题?

  1. 全面覆盖:我们涵盖从基本的React概念到高级模式的所有内容,确保您为任何面试场景做好充分准备。
  2. 实践、亲身实践学习:在旨在模拟面试条件的编码环境中解决真实的React挑战。
  3. 专家编写的解决方案:从经验丰富的工程师编写的高质量解释和最佳实践中学习,这些工程师拥有深厚的行业知识。
  4. 即时反馈:使用自动测试用例验证您的代码,以立即识别和纠正错误,从而加速您的学习过程。

这些问题如何为您取得成功做好准备

通过练习我们的React编码面试问题,您将:

  • 掌握核心概念:深入了解React基础知识、钩子和状态管理。
  • 增强解决问题的能力:应对需要批判性思维和系统方法来解决实际问题的挑战。
  • 建立信心:熟悉常见的React面试模式,减少焦虑并提高面试表现。
  • 应用最佳实践:学习用于构建组件、管理状态和优化应用程序性能的行业标准。

在您的React编码面试中脱颖而出

我们的React编码面试资源不仅仅是准备。它为您提供在任何面试场景中脱颖而出的技能和信心,无论您是前端工程师、全栈开发人员,还是探索React开发中的新职业机会。深入实践,在专家指导下完善您的解决方案,并建立作为React开发人员脱颖而出的专业知识。

相关列表

如果您正在寻找更具体的内容,请查看下面的其他问题列表: