Skip to content

Commit

Permalink
fixed: null-element is rendered to html
Browse files Browse the repository at this point in the history
  • Loading branch information
maddsua committed Jan 8, 2024
1 parent 15e1cc1 commit 36994e3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ abstract class JSXNode {

const renderChildren = (children: any[], renderProps?: RenderProps) => {

const asStrings = children.map(item => {
const asStrings: (string | undefined)[] = children.map(item => {

if (item instanceof JSXNode)
return item.render(renderProps);

switch (typeof item) {
case 'string': return item;
case 'number': return item.toString();
case 'object': return JSON.stringify(item);
case 'boolean': return item ? 'true' : 'false';
default: return null;
default: {
if (item !== null && item !== undefined)
return JSON.stringify(item);
} break;
}
});

return asStrings.filter(item => typeof item === 'string').join('');
return asStrings.filter(item => item?.length).join('');
};

class JSXFragmentNode extends JSXNode {
Expand Down

0 comments on commit 36994e3

Please sign in to comment.