Skip to content

Commit

Permalink
fix: better default serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Jan 23, 2025
1 parent b2b14de commit 4213413
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/exporters/serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function defaultSerializer(x: unknown): string | number | Date {
if (x instanceof Date || typeof x === 'number' || typeof x === 'string') {
return x;
}

return JSON.stringify(x);
}
6 changes: 2 additions & 4 deletions src/internalState/calcProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo } from 'react';
import { useTableMemo } from '../hooks/useTableMemo';
import { asString } from '../misc/helpers';
import type { Column, Id, InternalColumn, InternalTableProps, TableProps } from '../types';
import { defaultSerializer } from '../exporters/serializer';

const noopParentId = () => undefined;

Expand Down Expand Up @@ -71,10 +72,7 @@ export function calcProps<T>(props: TableProps<T>): InternalTableProps<T> {
`columns.${cacheKey}.renderCell`,
renderCell ?? defaults?.renderCell ?? asString,
),
exportCell:
exportCell ??
defaults?.exportCell ??
((x) => (x instanceof Date || typeof x === 'number' ? x : String(x))),
exportCell: exportCell ?? defaults?.exportCell ?? defaultSerializer,
sortBy: (
sortBy ??
defaults?.sortBy ?? [
Expand Down

0 comments on commit 4213413

Please sign in to comment.