phaser-jsx
Version:
Use JSX in Phaser.
36 lines (30 loc) • 772 B
text/typescript
import type { ComponentClass, FC, JSX } from 'react';
import type { Props } from '../types';
/**
* Creates an element.
*
* @param type - The `type` argument must be a valid component type.
* @param props - The `props` argument must either be an object or `null`.
* @param children - Zero or more child elements.
* @returns - Element object with properties `type` and `props`.
*/
export function createElement(
type: FC | ComponentClass,
props?: Props | null,
...children: JSX.Element[]
): JSX.Element {
if (!props) {
props = {};
}
if (children.length) {
props.children = children;
}
if (props.children && !Array.isArray(props.children)) {
props.children = [props.children];
}
return {
type,
props,
key: null,
};
}