2024-12-18 14:09:49 +08:00
|
|
|
import * as React from 'react';
|
2024-12-24 19:31:22 +08:00
|
|
|
import * as ReactDOM from 'react-dom';
|
2025-01-10 14:14:31 +08:00
|
|
|
import { render, unmount } from '@rc-component/util/lib/React/render';
|
2024-12-18 14:09:49 +08:00
|
|
|
|
2024-12-24 19:31:22 +08:00
|
|
|
import warning from '../_util/warning';
|
|
|
|
|
2024-12-18 14:09:49 +08:00
|
|
|
export type UnmountType = () => Promise<void>;
|
|
|
|
export type RenderType = (
|
|
|
|
node: React.ReactElement,
|
|
|
|
container: Element | DocumentFragment,
|
|
|
|
) => UnmountType;
|
|
|
|
|
|
|
|
const defaultReactRender: RenderType = (node, container) => {
|
2024-12-24 19:31:22 +08:00
|
|
|
// TODO: Remove in v6
|
|
|
|
// Warning for React 19
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
const majorVersion = parseInt(React.version.split('.')[0], 10);
|
2024-12-30 13:20:17 +08:00
|
|
|
const fullKeys = Object.keys(ReactDOM);
|
|
|
|
|
2024-12-24 19:31:22 +08:00
|
|
|
warning(
|
2024-12-30 13:20:17 +08:00
|
|
|
majorVersion < 19 || fullKeys.includes('createRoot'),
|
2024-12-24 19:31:22 +08:00
|
|
|
'compatible',
|
|
|
|
'antd v5 support React is 16 ~ 18. see https://u.ant.design/v5-for-19 for compatible.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-18 14:09:49 +08:00
|
|
|
render(node, container);
|
|
|
|
return () => {
|
|
|
|
return unmount(container);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
let unstableRender: RenderType = defaultReactRender;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Set React render function for compatible usage.
|
|
|
|
* This is internal usage only compatible with React 19.
|
|
|
|
* And will be removed in next major version.
|
|
|
|
*/
|
|
|
|
export function unstableSetRender(render: RenderType) {
|
|
|
|
unstableRender = render;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getReactRender() {
|
|
|
|
return unstableRender;
|
|
|
|
}
|