Skip to content

Commit 619e1e9

Browse files
authored
Update API client and add support for JSX component functions (#297)
* Support calling functions in JSX to build component * Update api client with latest OpenAPI spec
1 parent 6faa977 commit 619e1e9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/beige-dragons-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/runtime': minor
3+
---
4+
5+
Add support for using functions as components in JSX

.changeset/two-chefs-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/api': minor
3+
---
4+
5+
Update api client with latest OpenAPI spec

packages/runtime/src/contentkit-jsx.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function Fragment() {
88
/**
99
* JSX factory function, to be exported from the JSX package entry point.
1010
*/
11-
export function jsx(type: string | typeof Fragment, props: object) {
11+
export function jsx(type: string | typeof Fragment | ((props: object) => any), props: object) {
1212
let { children } = props;
1313

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

25+
if (typeof type === 'function') {
26+
return type(props);
27+
}
28+
2529
return {
2630
type,
2731
...props,

0 commit comments

Comments
 (0)