add service module
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
type JSXElement = {
|
||||
type: string | symbol;
|
||||
props: Record<string, any>;
|
||||
key?: string | number;
|
||||
};
|
||||
export function createDOMElement(jsxElement: JSXElement) {
|
||||
export function createDOMElement(jsxElement: JSX.Element) {
|
||||
// 如果 jsxElement 是 null, undefined 或者是布尔值,则直接跳过处理
|
||||
if (jsxElement == null || typeof jsxElement === 'boolean') {
|
||||
console.warn('Invalid JSX element:', jsxElement);
|
||||
return null;
|
||||
}
|
||||
|
||||
const { type, props } = jsxElement;
|
||||
|
||||
// React Fragment 的处理
|
||||
if (type === Symbol.for('react.fragment')) {
|
||||
const fragment = document.createDocumentFragment();
|
||||
@@ -31,8 +28,8 @@ export function createDOMElement(jsxElement: JSXElement) {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
const domElement = document.createElement(type as string);
|
||||
|
||||
const domElement = document.createElement(type);
|
||||
if (!props) return domElement;
|
||||
// 处理 props
|
||||
Object.keys(props).forEach((prop) => {
|
||||
if (prop === 'children') {
|
||||
|
||||
Reference in New Issue
Block a user