Skip to content

Commit bc5b573

Browse files
authored
Use live signal plain value (#800)
* Allow useLiveSignal to leverage plain values * Add changeset
1 parent 80712b1 commit bc5b573

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.changeset/green-doors-tease.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@preact/signals": patch
3+
"@preact/signals-react": patch
4+
---
5+
6+
Allow useLiveSignal to accept plain values

packages/preact/utils/src/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const Item = (props: any) => {
1515
: props.children;
1616
};
1717

18-
export function Show<T = boolean>(props: ShowProps<T>): ComponentChildren | null {
18+
export function Show<T = boolean>(
19+
props: ShowProps<T>
20+
): ComponentChildren | null {
1921
const value =
2022
typeof props.when === "function" ? props.when() : props.when.value;
2123
if (!value) return props.fallback || null;
@@ -60,9 +62,7 @@ export function For<T>(props: ForProps<T>): ComponentChildren | null {
6062
return createElement(Fragment, null, items);
6163
}
6264

63-
export function useLiveSignal<T>(
64-
value: Signal<T> | ReadonlySignal<T>
65-
): Signal<Signal<T> | ReadonlySignal<T>> {
65+
export function useLiveSignal<T>(value: T): Signal<T> {
6666
const s = useSignal(value);
6767
if (s.peek() !== value) s.value = value;
6868
return s;

packages/react/utils/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {
6565
return createElement(Fragment, { children: items });
6666
}
6767

68-
export function useLiveSignal<T>(value: Signal<T> | ReadonlySignal<T>) {
68+
export function useLiveSignal<T>(value: T): Signal<T> {
6969
const s = useSignal(value);
7070
if (s.peek() !== value) s.value = value;
7171
return s;

0 commit comments

Comments
 (0)