React Version
约 2 分钟阅读
标签:版本
| ver | date | notes |
|---|---|---|
| React 19 | RSC, async, WebComponents | |
| React 18 | 2022-03-29 | ReactDOM.createRoot |
| React 17 | 2020-10-20 | |
| React 16.8 | 2019-02-06 | Hooks |
Roadmap
- 支持自定义元素属性 - #11347GitHub Issuefacebook/react#11347
- 更好支持 WebComponents
- React 19
- Add a "module" entry in package.json #10021GitHub Issuefacebook/react#10021
- React 作为 ESM
- 目前主要问题是 cjs 和 esm 混合可能导致各种问题 - react 不能轻易变动
- 目前大的生态在放弃 cjs - 还是会保留 umd
- Formalize top-level ES exports #11503GitHub Issuefacebook/react#11503
- 解决
import * as React问题 - 目前 ESM 内已经使用
import React from 'react';- 2020-02 #18102GitHub PRfacebook/react#18102
- 解决
- Support for reparenting #3965GitHub Issuefacebook/react#3965
- Remove Factory Components #13560GitHub Issuefacebook/react#13560
- deprecated in React 17.x
- create-element-changes.mdGitHub 文件reactjs/rfcs/text/0000-create-element-changes.md
- 2022-06 What We've Been Working On
- Server Components
- Asset Loading
- SSR 优化
- React Optimizing Compiler
- Offscreen
- Transition Tracing
React 19
- React Compiler
- 自动 memo
React.lazy- playground.react.dev
forwardRef- 支持 ref 作为 props
- Server Component
- async 组件
- WebComponents
- custom element attributes/properties
- facebook/react#11347GitHub Issuefacebook/react#11347
React 18
- FC 默认无 children 属性
- automatic batching
- concurrent feature
- startTransition
- useTransition
- useDeferredValue
- 类似 useDebounedValue 但结合 React 并行进行渲染,而不是自行决定 delay 时间
- 提升 UX 体验
- APIs for library
- useId - for ARIA - aria-labaledby
- 生成表单元素
- useSyncExternalStoreGitHubreactwg/react-18/discussions/86
- useInsertionEffect
- streaming server renderer
- suspense on server
- 细粒度控制 hydration
- hydration 不会阻塞浏览器,可能会被中断,根据用户操作进行优先
- 细粒度控制 hydration
- suspense on server
- 实验特性
- server component - 可通过 nextjs 使用
- React.memo - UX vs DX
- React Forget - 自动 memo 的编译器
- 参考
- What's New in React 18? HNHacker NewsHacker News #28696748Hacker News
- ReactDOM.render -> ReactDOM.createRoot
// before
ReactDOM.render(<App />, el);
// after
const root = ReactDOM.createRoot(el);
root.render(<App />);
// 服务端渲染 为 aria 生成唯一 ID
const MyInputs = () => {
const id = useId();
return (
<>
<label htmlForm={`${id}-name`}>Name</label>
<input id={`${id}-name`} />
</>
);
};React 17
- 内部结构变化,为下一个版本做准备 - 无功能变化
- children 处理有变化 - 总是作为 props 传递
- 早期区分是为了在 DEV 时区别静态和动态内容
- key 独立传递 -
jsx('div', props, key) - depreacted componentWillMount, componentWillReceiveProps, componentWillUpdate
- polyfill react-lifecycles-compatGitHubreactjs/react-lifecycles-compat
- 不再需要对事件进行 persist
<input
onChange={(e) => {
e.persist(); // 17 之后不再需要
update((s) => {
// 之前如果不 persist 可能为 null
s.value = e.target.value;
});
}}
/>- 新的 JSX 转换 - jsx 不再需要引入 React
- react/jsx-runtime
- react/jsx-dev-runtime
- 也可以与其他 JSX 项目共享
import { jsx as _jsx } from 'react/jsx-runtime';
function App() {
// return React.createElement('h1', null, 'Hello world');
return _jsx('h1', { children: 'Hello world' });
}- React DOM
ReactDOM.render(<App />, rootNode)会在 rootNode 监听事件 - 之前是 document 上监听
React 16.8
- 新增 Functional Component
- 新增 Hooks
关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
GitHub9 条
- facebook/react#11347github.com/facebook/react/issues/11347
- facebook/react#10021github.com/facebook/react/issues/10021
- facebook/react#11503github.com/facebook/react/issues/11503
- facebook/react#13560github.com/facebook/react/issues/13560
- facebook/react#18102github.com/facebook/react/pull/18102
- facebook/react#3965github.com/facebook/react/issues/3965
- reactjs/react-lifecycles-compatgithub.com/reactjs/react-lifecycles-compat
- reactjs/rfcs/text/0000-create-element-changes.mdgithub.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md
- reactwg/react-18/discussions/86github.com/reactwg/react-18/discussions/86
Hacker News1 条
- Hacker News #28696748HN #28696748
其他外链2 条
- playground.react.devplayground.react.dev/
- reactjs.org/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.htmlreactjs.org/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.html