Skip to content

Commit

Permalink
Add return types to react runtime exports
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Nov 15, 2023
1 parent 2f17eb8 commit edf4fae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/react/runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { signal, computed, effect, Signal } from "@preact/signals-core";
import {
signal,
computed,
effect,
Signal,
ReadonlySignal,
} from "@preact/signals-core";
import { useRef, useMemo, useEffect } from "react";
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
import { isAutoSignalTrackingInstalled } from "./auto";
Expand Down Expand Up @@ -191,22 +197,22 @@ Object.defineProperties(Signal.prototype, {
ref: { configurable: true, value: null },
});

export function useSignals() {
export function useSignals(): EffectStore {
if (isAutoSignalTrackingInstalled) return emptyEffectStore;
return _useSignalsImplementation();
}

export function useSignal<T>(value: T) {
export function useSignal<T>(value: T): Signal<T> {
return useMemo(() => signal<T>(value), Empty);
}

export function useComputed<T>(compute: () => T) {
export function useComputed<T>(compute: () => T): ReadonlySignal<T> {
const $compute = useRef(compute);
$compute.current = compute;
return useMemo(() => computed<T>(() => $compute.current()), Empty);
}

export function useSignalEffect(cb: () => void | (() => void)) {
export function useSignalEffect(cb: () => void | (() => void)): void {
const callback = useRef(cb);
callback.current = cb;

Expand Down

0 comments on commit edf4fae

Please sign in to comment.