Skip to content

Commit

Permalink
fix: don't pass undefined as item into style function
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Apr 3, 2024
1 parent ad4b720 commit 119e9bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Cell = memo(function Cell<T>({ itemId, rowIndex }: { itemId: Id; ro

useLayoutEffect(() => table.getState().props.debugRender?.('render cell', itemId, columnId));
const className = useTheme((t) => cx(...calcClassNames(t.classes, item?.value, rowIndex)));
const styles = useTheme((t) => calcCss(t.styles, item?.value, rowIndex));
const styles = useTheme((t) => calcCss<T>(t.styles, item?.value, rowIndex));

if (!column || !item) return null;

Expand Down
2 changes: 1 addition & 1 deletion src/components/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Row = memo(function Row<T>({

return {
className: cx(...calcClassNames(classes, item?.value, rowIndex)),
css_: calcCss(styles, item?.value, rowIndex),
css_: calcCss<T>(styles, item?.value, rowIndex),
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
hasChildren: !!item?.children.length,
hasDeferredChildren: item && state.props.hasDeferredChildren?.(item.value),
Expand Down
8 changes: 6 additions & 2 deletions src/misc/calcClassNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ export function calcClassNames<T>(

export function calcCss<T>(
styles: MemoizedTableTheme<T>['styles'] | undefined,
item: T,
item: T | undefined,
index: number,
) {
return [
styles?.cell instanceof Function ? styles.cell(item, index) : styles?.cell,
styles?.cell instanceof Function
? item !== undefined
? styles.cell(item, index)
: undefined
: styles?.cell,
index % 2 === 0 && styles?.evenCell,
index % 2 === 1 && styles?.oddCell,
];
Expand Down

0 comments on commit 119e9bd

Please sign in to comment.