UNPKG

@deckyfx/dioxus-react-bridge

Version:

React hooks and components for Dioxus IPC communication - lightweight bridge between React and Rust

65 lines 1.93 kB
/** * React Context Provider for Rust IPC * * Provides access to the unified window.dioxusBridge HTTP-like IPC system * and manages event forwarding to the IPCBridge event system. */ import React from 'react'; import type { IpcResponse, IpcFetchOptions } from '../types/ipc-types'; /** * Context value interface */ interface RustIPCContextValue { /** Whether window.dioxusBridge is ready */ isReady: boolean; /** * HTTP-like fetch for IPC communication * @param url - IPC URL (e.g., "ipc://endpoint/path") * @param options - Request options (method, headers, body) * @returns Promise resolving to IPC response */ fetch: <T = any>(url: string, options?: IpcFetchOptions) => Promise<IpcResponse<T>>; } /** * RustIPCProvider - Wraps the app and provides unified IPC functionality * * Uses the HTTP-like window.dioxusBridge.fetch() API and intercepts * window.dioxusBridge.rustEmit() to forward events to IPCBridge. * * @example * ```tsx * <RustIPCProvider> * <App /> * </RustIPCProvider> * ``` */ export declare function RustIPCProvider({ children }: { children: React.ReactNode; }): import("react/jsx-runtime").JSX.Element; /** * Hook to access RustIPC context * * Provides access to the fetch function for HTTP-like IPC requests. * * @returns Context value with isReady flag and fetch function * @throws Error if used outside RustIPCProvider * * @example * ```tsx * function MyComponent() { * const { fetch, isReady } = useRustIPC(); * * const handleClick = async () => { * const response = await fetch('ipc://calculator/fibonacci?number=10'); * console.log(response.body.result); * }; * * if (!isReady) return <div>Loading...</div>; * * return <button onClick={handleClick}>Calculate</button>; * } * ``` */ export declare function useRustIPC(): RustIPCContextValue; export {}; //# sourceMappingURL=RustIPCContext.d.ts.map