React 18更新相关的类型改变
Published on February 22, 2023Updated on March 23, 2024
Loading content...
这是个探索性的分享,听完你可以了解到
17
18
17
TypeScripttype ReactText = string | number; type ReactChild = ReactElement | ReactText; /** * @deprecated Use either `ReactNode[]` if you need an array or `Iterable<ReactNode>` if its passed to a host component. */ interface ReactNodeArray extends ReadonlyArray<ReactNode> {} type ReactFragment = {} | Iterable<ReactNode>; type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;
18
TypeScript/** * @deprecated - This type is not relevant when using React. Inline the type instead to make the intent clear. */ type ReactText = string | number; /** * @deprecated - This type is not relevant when using React. Inline the type instead to make the intent clear. */ type ReactChild = ReactElement | string | number; /** * @deprecated Use either `ReactNode[]` if you need an array or `Iterable<ReactNode>` if its passed to a host component. */ interface ReactNodeArray extends ReadonlyArray<ReactNode> {} type ReactFragment = Iterable<ReactNode>; type ReactNode = ReactElement | string | number | ReactFragment | ReactPortal | boolean | null | undefined;
https://reactjs.org/docs/fragments.html
搜索了一些内容还是找不到他的具体实现逻辑。 但回顾类型的时候,有了些体会。
TypeScripttype ReactFragment = Iterable<ReactNode>;
从React提供的类型和React利用 ReactFragment 的视角来看,这就是一个可以迭代的对象而已,并且支持 key 的属性
在 DOM 上应该没啥映射关系,在 React 虚拟 DOM 中用得上,比对啥的(猜测)