Skip to content

Commit

Permalink
Update API client and add support for JSX component functions (#297)
Browse files Browse the repository at this point in the history
* Support calling functions in JSX to build component

* Update api client with latest OpenAPI spec
  • Loading branch information
SamyPesse authored Nov 15, 2023
1 parent 6faa977 commit 619e1e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/beige-dragons-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/runtime': minor
---

Add support for using functions as components in JSX
5 changes: 5 additions & 0 deletions .changeset/two-chefs-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/api': minor
---

Update api client with latest OpenAPI spec
6 changes: 5 additions & 1 deletion packages/runtime/src/contentkit-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function Fragment() {
/**
* JSX factory function, to be exported from the JSX package entry point.
*/
export function jsx(type: string | typeof Fragment, props: object) {
export function jsx(type: string | typeof Fragment | ((props: object) => any), props: object) {
let { children } = props;

if (typeof children !== 'undefined' && !Array.isArray(children)) {
Expand All @@ -22,6 +22,10 @@ export function jsx(type: string | typeof Fragment, props: object) {
return children;
}

if (typeof type === 'function') {
return type(props);
}

return {
type,
...props,
Expand Down

0 comments on commit 619e1e9

Please sign in to comment.