@signaldb/react
Version:
SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in
39 lines (38 loc) • 1.35 kB
TypeScript
import type { DependencyList } from 'react';
interface StopComputation {
(): void;
}
interface ReactiveEffect {
(reactiveFunction: () => void): StopComputation;
}
/**
* Creates a custom React hook for managing reactive computations with a given reactive effect.
* This hook allows for automatic tracking and re-rendering of React components when reactive dependencies change.
* @param effectFunction - A function that runs a reactive computation and provides a way to stop the computation.
* @returns A React hook (`useReactivity`) for managing reactive computations.
* @example
* import { createUseReactivityHook } from './createUseReactivityHook';
*
* example with @maverick-js/signals effect function
* import { effect } from @maverick-js/signals
*
* // Create the custom hook
* const useReactivity = createUseReactivityHook(effect);
*
* // Use the custom hook in a component
* function MyComponent() {
* const reactiveData = useReactivity(() => {
* return myReactiveCollection.find().fetch();
* }, []);
*
* return (
* <div>
* {reactiveData.map(item => (
* <div key={item.id}>{item.name}</div>
* ))}
* </div>
* );
* }
*/
export declare function createUseReactivityHook(effectFunction: ReactiveEffect): <T>(reactiveFunction: () => T, deps?: DependencyList) => T;
export {};