Skip to content

Commit 48ea0df

Browse files
committed
Normalize all JSX callbacks to support functions
1 parent 403fb7a commit 48ea0df

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

src/index.js

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,10 @@ export default React.createClass({
453453
}}
454454
{...rest}
455455
>
456-
{typeof column.header === 'function' ? (
457-
<column.header
458-
data={sortedData}
459-
column={column}
460-
/>
461-
) : column.header}
456+
{_.normalizeComponent(column.header, {
457+
data: sortedData,
458+
column: column
459+
})}
462460
</ThComponent>
463461
)
464462
}
@@ -537,12 +535,10 @@ export default React.createClass({
537535
{column.pivotColumns.map((pivotColumn, i) => {
538536
return (
539537
<span key={pivotColumn.id}>
540-
{typeof pivotColumn.header === 'function' ? (
541-
<pivotColumn.header
542-
data={sortedData}
543-
column={pivotColumn}
544-
/>
545-
) : pivotColumn.header}
538+
{_.normalizeComponent(pivotColumn.header, {
539+
data: sortedData,
540+
column: column
541+
})}
546542
{i < column.pivotColumns.length - 1 && (
547543
<ExpanderComponent />
548544
)}
@@ -589,12 +585,10 @@ export default React.createClass({
589585
}}
590586
{...rest}
591587
>
592-
{typeof column.header === 'function' ? (
593-
<column.header
594-
data={sortedData}
595-
column={column}
596-
/>
597-
) : column.header}
588+
{_.normalizeComponent(column.header, {
589+
data: sortedData,
590+
column: column
591+
})}
598592
</ThComponent>
599593
)
600594
}
@@ -627,7 +621,6 @@ export default React.createClass({
627621
{...trProps.rest}
628622
>
629623
{allVisibleColumns.map((column, i2) => {
630-
const Cell = column.render
631624
const show = typeof column.show === 'function' ? column.show() : column.show
632625
const width = _.getFirstDefined(column.width, column.minWidth)
633626
const maxWidth = _.getFirstDefined(column.width, column.maxWidth)
@@ -745,17 +738,10 @@ export default React.createClass({
745738
}}
746739
{...tdProps.rest}
747740
>
748-
{typeof Cell === 'function' ? (
749-
Cell.prototype.isReactComponent ? (
750-
<Cell
751-
{...rowInfo}
752-
value={rowInfo.rowValues[column.id]}
753-
/>
754-
) : Cell({
755-
...rowInfo,
756-
value: rowInfo.rowValues[column.id]
757-
})
758-
) : rowInfo.rowValues[column.id]}
741+
{_.normalizeComponent(column.render, {
742+
...rowInfo,
743+
value: rowInfo.rowValues[column.id]
744+
}, rowInfo.rowValues[column.id])}
759745
</TdComponent>
760746
)
761747
})}

src/utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default {
1717
isArray,
1818
splitProps,
1919
compactObject,
20-
isSortingDesc
20+
isSortingDesc,
21+
normalizeComponent
2122
}
2223

2324
function get (obj, path, def) {
@@ -189,3 +190,13 @@ function compactObject (obj) {
189190
function isSortingDesc (d) {
190191
return !!(d.sort === 'desc' || d.desc === true || d.asc === false)
191192
}
193+
194+
function normalizeComponent (Comp, params, fallback = Comp) {
195+
return typeof Comp === 'function' ? (
196+
Comp.prototype.isReactComponent ? (
197+
<Comp
198+
{...params}
199+
/>
200+
) : Comp(params)
201+
) : fallback
202+
}

0 commit comments

Comments
 (0)