|
1 | 1 | import { options, Component, isValidElement, Fragment } from "preact"; |
2 | | -import { useRef, useMemo, useEffect } from "preact/hooks"; |
| 2 | +import { useRef, useEffect, useState } from "preact/hooks"; |
3 | 3 | import { |
4 | 4 | signal, |
5 | 5 | computed, |
@@ -92,7 +92,7 @@ function SignalValue(this: AugmentedComponent, { data }: { data: Signal }) { |
92 | 92 | const currentSignal = useSignal(data); |
93 | 93 | currentSignal.value = data; |
94 | 94 |
|
95 | | - const [isText, s] = useMemo(() => { |
| 95 | + const [[isText, s]] = useState(() => { |
96 | 96 | let self = this; |
97 | 97 | // mark the parent component as having computeds so it gets optimized |
98 | 98 | let v = this.__v; |
@@ -139,7 +139,7 @@ function SignalValue(this: AugmentedComponent, { data }: { data: Signal }) { |
139 | 139 | }; |
140 | 140 |
|
141 | 141 | return [isText, wrappedSignal]; |
142 | | - }, []); |
| 142 | + }); |
143 | 143 |
|
144 | 144 | // Rerender the component whenever `data.value` changes from a VNode |
145 | 145 | // to another VNode, from text to a VNode, or from a VNode to text. |
@@ -387,17 +387,16 @@ Component.prototype.shouldComponentUpdate = function ( |
387 | 387 | export function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>; |
388 | 388 | export function useSignal<T = undefined>(): Signal<T | undefined>; |
389 | 389 | export function useSignal<T>(value?: T, options?: SignalOptions<T>) { |
390 | | - return useMemo( |
391 | | - () => signal<T | undefined>(value, options as SignalOptions), |
392 | | - [] |
393 | | - ); |
| 390 | + return useState(() => |
| 391 | + signal<T | undefined>(value, options as SignalOptions) |
| 392 | + )[0]; |
394 | 393 | } |
395 | 394 |
|
396 | 395 | export function useComputed<T>(compute: () => T, options?: SignalOptions<T>) { |
397 | 396 | const $compute = useRef(compute); |
398 | 397 | $compute.current = compute; |
399 | 398 | (currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS; |
400 | | - return useMemo(() => computed<T>(() => $compute.current(), options), []); |
| 399 | + return useState(() => computed<T>(() => $compute.current(), options))[0]; |
401 | 400 | } |
402 | 401 |
|
403 | 402 | function safeRaf(callback: () => void) { |
|
0 commit comments