UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

45 lines (44 loc) 1.5 kB
import { DependencyList } from "react"; import type { Signal } from "@preact/signals-core"; /** * Hook to subscribe to a signal and get the current value. * @param signal - Signal to subscribe to * @returns Current value of the signal * * @example * ```tsx * const geometry = useSignal(block.$geometry); * ``` */ export declare function useSignal<T>(signal: Signal<T>): T; /** * Hook to subscribe to a computed signal and get the current value. * @param compute - Computed function to subscribe to * @param deps - Dependencies to subscribe to * @returns Current value of the computed signal * * @example * ```tsx * const geometry = useComputedSignal(() => block.$geometry.value, [block]); * ``` */ export declare function useComputedSignal<T>(compute: () => T, deps: DependencyList): T; /** * Hook to subscribe to a signal and get the current value. * @param effectFn - Effect function to subscribe to * @param deps - Dependencies recreate the effect when they change * @returns Current value of the signal * * @example * ```tsx * useSignalEffect(() => { * console.log(block.$geometry.value); * }, [block]); * ``` */ export declare function useSignalEffect(effectFn: () => void, deps: DependencyList): void; /** * Like {@link useSignalEffect}, but runs the subscription setup in `useLayoutEffect` * so the effect fires synchronously after DOM updates and before paint. */ export declare function useSignalLayoutEffect(effectFn: () => void, deps: DependencyList): void;