@quantajs/react
Version:
React integration for QuantaJS - A compact, scalable, and developer-friendly state management library for React applications.
99 lines (76 loc) • 3.67 kB
TypeScript
import { ActionDefinition } from '@quantajs/core';
import { computed } from '@quantajs/core';
import { Context } from 'react';
import { createStore } from '@quantajs/core';
import { GetterDefinitions } from '@quantajs/core';
import { JSX } from 'react/jsx-runtime';
import { logger } from '@quantajs/core';
import { RawActions } from '@quantajs/core';
import { reactive } from '@quantajs/core';
import { ReactNode } from 'react';
import { StateDefinition } from '@quantajs/core';
import { StoreInstance } from '@quantajs/core';
import { StoreSubscriber } from '@quantajs/core';
import { watch } from '@quantajs/core';
export { ActionDefinition }
export { computed }
export { createStore }
export { GetterDefinitions }
export { logger }
export declare const QuantaContext: Context<QuantaContextValue>;
declare interface QuantaContextValue {
stores: {
[name: string]: StoreInstance<any, any, any>;
};
}
export declare const QuantaDevTools: ({ visible }: QuantaDevToolsProps) => null;
declare interface QuantaDevToolsProps {
/**
* Whether to show the DevTools.
* If not provided, it attempts to detect development environment.
* Pass `true` to force show, `false` to force hide.
*/
visible?: boolean;
}
/**
* Provider component that makes a QuantaJS store available to all child components
* @param stores - The QuantaJS stores instances to provide
* @param children - Child components that can access the stores
*/
export declare function QuantaProvider({ stores, children }: QuantaProviderProps): JSX.Element;
declare interface QuantaProviderProps {
stores: {
[key: string]: StoreInstance<any, any, any>;
};
children: ReactNode;
}
export { reactive }
export { StateDefinition }
export { StoreInstance }
export { StoreSubscriber }
/**
* Hook to create a QuantaJS store instance within a React component
* Creates store only once and reuses it across re-renders
*/
export declare function useCreateStore<S extends object, GDefs extends Record<string, (state: S) => any> = {}, A extends Record<string, (...args: any[]) => any> = {}>(name: string, state: StateDefinition<S>, getters?: GetterDefinitions<S, GDefs>, actions?: ActionDefinition<S, GDefs, A>): StoreInstance<S, GDefs, A>;
/**
* Hook to access the QuantaJS store from the context
* @returns The store instance from the nearest QuantaProvider
* @throws Error if used outside of QuantaProvider
*/
export declare function useQuantaContext(): QuantaContextValue;
/**
* Hook to subscribe to a QuantaJS store and get reactive updates
* Simple implementation that relies on QuantaJS core's reactivity system
*/
export declare function useQuantaStore<S extends object, GDefs extends Record<string, (state: S) => any> = {}, A extends RawActions = {}>(store: StoreInstance<S, GDefs, A>): StoreInstance<S, GDefs, A>;
export declare function useQuantaStore<S extends object, GDefs extends Record<string, (state: S) => any> = {}, A extends RawActions = {}, T = any>(store: StoreInstance<S, GDefs, A>, selector: (store: StoreInstance<S, GDefs, A>) => T): T;
/**
* Hook to access and subscribe to the QuantaJS store from context
* @param name - The name of the store to access
* @param selector - Optional selector function to pick specific parts of the store
* @returns The store instance or selected value that updates reactively
*/
export declare function useStore<T = any>(name: string, selector?: (store: StoreInstance<any, any, any>) => T): T extends undefined ? StoreInstance<any, any, any> : T;
export { watch }
export { }