Skip to content

Commit 0a03ea3

Browse files
committed
fix: better flexRender utility (supports JSX elements now)
1 parent 0aa55da commit 0a03ea3

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

examples/kitchen-sink/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
304304
disablePageResetOnDataChange,
305305
},
306306
useFilters,
307-
useSortBy,
308307
useGroupBy,
308+
useSortBy,
309309
useExpanded,
310310
usePagination,
311311
useRowSelect

src/utils.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,22 @@ export function getElementDimensions(element) {
265265
}
266266

267267
export function flexRender(Comp, props) {
268-
if (typeof Comp === 'function' || typeof Comp === 'object') {
269-
return <Comp {...props} />
270-
}
271-
return Comp
268+
return isReactComponent(Comp) ? <Comp {...props} /> : Comp
269+
}
270+
271+
function isClassComponent(component) {
272+
return (
273+
typeof component === 'function' &&
274+
!!Object.getPrototypeOf(component).isReactComponent
275+
)
276+
}
277+
278+
function isFunctionComponent(component) {
279+
return typeof component === 'function'
280+
}
281+
282+
function isReactComponent(component) {
283+
return isClassComponent(component) || isFunctionComponent(component)
272284
}
273285

274286
export const mergeProps = (...groups) => {

0 commit comments

Comments
 (0)