Skip to content

Commit

Permalink
simplify preact flex render types
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jan 6, 2025
1 parent f64aea1 commit 8b3ebb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/preact/sorting/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function App() {
{
accessorKey: 'progress',
header: 'Profile Progress',
// enableSorting: false, //disable sorting for this column
// enableSorting: false, // disable sorting for this column
},
{
accessorKey: 'rank',
Expand Down
15 changes: 4 additions & 11 deletions packages/preact-table/src/FlexRender.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import type { ComponentType, VNode } from 'preact'
import type { ComponentChild, ComponentType } from 'preact'

export type Renderable<TProps> =
| VNode<TProps>
| ComponentType<TProps>
| undefined
| null
| string
| number
| boolean
export type Renderable<TProps> = ComponentChild | ComponentType<TProps>

function isPreactComponent<TProps>(
component: unknown,
Expand Down Expand Up @@ -46,11 +39,11 @@ function isExoticComponent(component: any) {
export function flexRender<TProps extends object>(
Comp: Renderable<TProps> | null,
props: TProps,
): VNode<TProps> | Element | null {
): ComponentChild | Element | null {
return !Comp ? null : isPreactComponent<TProps>(Comp) ? (
<Comp {...props} />
) : (
(Comp as VNode<TProps> | Element | null)
Comp
)
}

Expand Down

0 comments on commit 8b3ebb9

Please sign in to comment.