Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: allow string for children in h function
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowtime2000 committed Nov 25, 2020
1 parent 564deb8 commit 4823ddd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/vdom/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const VNodeTypes: Record<string, VNodeType> = {
DYNAMIC: 2, // dynamic VNode (needs patch every time view changes)
};

export const h = (selector: string, children?: (VNode | string)[], props?: VNodeProps): VNode => {
export const h = (selector: string, children?: (VNode | string)[] | string, props?: VNodeProps): VNode => {
// Splits selector into tokens containing id, className, and other attrs
const tokens = selector.split(/(?=\.)|(?=#)|(?=\[)/);
const tag = tokens[0];
Expand Down Expand Up @@ -51,7 +51,7 @@ export const h = (selector: string, children?: (VNode | string)[], props?: VNode

return {
tag,
children: children || [],
children: typeof children === 'string' ? [children] : (children ? children : []),
props: {
attributes: props?.attributes || attributes,
directives: props?.directives || directives,
Expand Down

0 comments on commit 4823ddd

Please sign in to comment.