Skip to content

Commit 91a2c2d

Browse files
committed
types: Widen util component types to accept all child node content
1 parent a237b61 commit 91a2c2d

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

packages/preact/utils/src/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ReadonlySignal, Signal } from "@preact/signals-core";
22
import { useSignal } from "@preact/signals";
3-
import { Fragment, createElement, JSX } from "preact";
3+
import { Fragment, createElement, ComponentChildren } from "preact";
44
import { useMemo } from "preact/hooks";
55

66
interface ShowProps<T = boolean> {
77
when: Signal<T> | ReadonlySignal<T> | (() => T);
8-
fallback?: JSX.Element;
9-
children: JSX.Element | ((value: NonNullable<T>) => JSX.Element);
8+
fallback?: ComponentChildren;
9+
children: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);
1010
}
1111

1212
const Item = (props: any) => {
@@ -15,7 +15,7 @@ const Item = (props: any) => {
1515
: props.children;
1616
};
1717

18-
export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {
18+
export function Show<T = boolean>(props: ShowProps<T>): ComponentChildren | null {
1919
const value =
2020
typeof props.when === "function" ? props.when() : props.when.value;
2121
if (!value) return props.fallback || null;
@@ -27,11 +27,11 @@ interface ForProps<T> {
2727
| Signal<Array<T>>
2828
| ReadonlySignal<Array<T>>
2929
| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);
30-
fallback?: JSX.Element;
31-
children: (value: T, index: number) => JSX.Element;
30+
fallback?: ComponentChildren;
31+
children: (value: T, index: number) => ComponentChildren;
3232
}
3333

34-
export function For<T>(props: ForProps<T>): JSX.Element | null {
34+
export function For<T>(props: ForProps<T>): ComponentChildren | null {
3535
const cache = useMemo(() => new Map(), []);
3636
let list = (
3737
(typeof props.each === "function" ? props.each() : props.each) as Signal<

packages/react/utils/src/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ReadonlySignal, Signal } from "@preact/signals-core";
22
import { useSignal } from "@preact/signals-react";
33
import { useSignals } from "@preact/signals-react/runtime";
4-
import { Fragment, createElement, useMemo } from "react";
4+
import { Fragment, createElement, useMemo, ReactNode } from "react";
55

66
interface ShowProps<T = boolean> {
77
when: Signal<T> | ReadonlySignal<T> | (() => T);
8-
fallback?: JSX.Element;
9-
children: JSX.Element | ((value: NonNullable<T>) => JSX.Element);
8+
fallback?: ReactNode;
9+
children: ReactNode | ((value: NonNullable<T>) => ReactNode);
1010
}
1111

1212
const Item = (props: any) => {
@@ -16,7 +16,7 @@ const Item = (props: any) => {
1616
: props.children;
1717
};
1818

19-
export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {
19+
export function Show<T = boolean>(props: ShowProps<T>): ReactNode | null {
2020
useSignals();
2121
const value =
2222
typeof props.when === "function" ? props.when() : props.when.value;
@@ -29,11 +29,11 @@ interface ForProps<T> {
2929
| Signal<Array<T>>
3030
| ReadonlySignal<Array<T>>
3131
| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);
32-
fallback?: JSX.Element;
33-
children: (value: T, index: number) => JSX.Element;
32+
fallback?: ReactNode;
33+
children: (value: T, index: number) => ReactNode;
3434
}
3535

36-
export function For<T>(props: ForProps<T>): JSX.Element | null {
36+
export function For<T>(props: ForProps<T>): ReactNode | null {
3737
useSignals();
3838
const cache = useMemo(() => new Map(), []);
3939
let list = (

0 commit comments

Comments
 (0)