Skip to content

Commit

Permalink
feat(Template): allow template functions to return a React element
Browse files Browse the repository at this point in the history
  • Loading branch information
VonD committed Feb 9, 2016
1 parent 0f9296d commit 748077d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/components/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ function Template(props) {
}

const otherProps = omit(props, keys(Template.propTypes));
const isElement = React.isValidElement(content);

if (React.isValidElement(content)) {
return (
<div
{...otherProps}
className={props.cssClass}
>{content}</div>
);
}

return (
<div
{...otherProps}
className={props.cssClass}
dangerouslySetInnerHTML={isElement ? null : {__html: content}}
>
{isElement ? content : null}
</div>
dangerouslySetInnerHTML={{__html: content}}
/>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/Template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Template', () => {
const out = renderer.getRenderOutput();

const content = 'it also works with functions';
expect(out).toEqualJSX(<div className={undefined} dangerouslySetInnerHTML={null}><p>{content}</p></div>);
expect(out).toEqualJSX(<div className={undefined}><p>{content}</p></div>);
});

it('can configure compilation options', () => {
Expand Down

0 comments on commit 748077d

Please sign in to comment.