React 的优势是什么
React advantage
一句话:声明式 + 组件化 + 单向数据流—— 你描述「界面应该长什么样」, React 负责把 DOM 变成那样。
- 声明式—— 你写
{items.map(...)}, 不写「找到 ul、创建 li、appendChild」。省掉的是「怎么从状态 A 变到状态 B」这类过程代码, 而这正是 bug 最多的地方。 - 组件化—— UI 拆成可复用、 可独立测试的单元。
- 单向数据流—— props 往下、事件往上。 出问题时排查路径是确定的: 数据只可能从一个方向来。
- 生态—— Router、 状态库、Next.js、React Native (同一套心智模型能写移动端)。
会追问缺点(一定要准备): 只是个视图库,路由和状态都要自己选,选型成本高; 性能优化要手动(memo /useMemo,React 19 之前没有自动记忆化); JSX 和 hooks 规则对新手有门槛;版本迁移的心智负担不小(class → hooks → Server Components)。
In one line: declarative + component-based + one-way data flow — you describe what the UI should look like and React makes the DOM match.
- Declarative — you write
{items.map(...)}, not “find the ul, create an li, appendChild”. What you drop is the step-by-step code for getting from state A to state B, and that is where most bugs live. - Components — the UI splits into reusable units you can test on their own.
- One-way data flow — props go down, events go up. When something breaks, there is exactly one path to trace: the data can only have come from one direction.
- Ecosystem — Router, state libraries, Next.js, React Native (the same mental model gets you a mobile app).
They will ask for the downsides (have them ready): it is only a view library, so you pick the router and the state layer yourself — the cost of those decisions is real; performance work is manual (memo / useMemo; there was no automatic memoization before React 19); JSX and the hook rules are a hurdle for beginners; and version migrations carry a lot of mental load (class → hooks → Server Components).