@realm/react
Version:
React specific hooks and implementation helpers for Realm
56 lines • 3.62 kB
TypeScript
import React from "react";
import Realm, { App } from "realm";
import { RestrictivePick } from "./helpers";
/** Mutually exclusive props for the AppProvider component when using a {@link Realm.AppConfiguration} */
type AppProviderWithConfigurationProps = Omit<Realm.AppConfiguration, "app"> & {
/**
* A ref to the App instance. This is useful if you need to access the App
* instance outside of a component that uses the App hooks.
*/
appRef?: React.MutableRefObject<Realm.App | null>;
children: React.ReactNode;
};
/** Props the AppProvider component when using an existing {@link Realm.App} instance */
type AppProviderWithAppProps = {
app: Realm.App;
children: React.ReactNode;
};
/** Combined props for the AppProvider component, used when defining mutually exclusive props */
type AppProviderProps = AppProviderWithAppProps & AppProviderWithConfigurationProps;
/** Mutually exclusive props for the AppProvider component when using an existing {@link Realm.App} instance */
type DynamicAppProviderWithAppProps = RestrictivePick<AppProviderProps, keyof AppProviderWithAppProps>;
/** Mutually exclusive props for the AppProvider component when using a {@link Realm.AppConfiguration} */
type DynamicAppProviderWithConfigurationProps = RestrictivePick<AppProviderProps, keyof AppProviderWithConfigurationProps>;
/**
* Props for the AppProvider component. You can either pass an existing {@link Realm.App} through the `app` prop
* or props that replicate the {@link Realm.AppConfiguration} that is used to create a Realm.App instance.
*/
type DynamicAppProviderProps = DynamicAppProviderWithAppProps | DynamicAppProviderWithConfigurationProps;
/**
* React component providing a Realm App instance on the context for the
* sync hooks to use. An `AppProvider` is required for an app to use the hooks.
* @param props - Either the {@link Realm.AppConfiguration} for App Services passed as props **or** the {@link Realm.App} passed through the `app` prop.
* @param appRef - Provides a ref to the app instance, which can be used to access the app instance outside of the React component tree. **Not available when using the `app` prop**.
*/
export declare function AppProvider(props: DynamicAppProviderProps): React.ReactNode;
/**
* React component providing a Realm App instance on the context for the
* sync hooks to use. An `AppProvider` is required for an app to use the hooks.
* @param props - The {@link Realm.AppConfiguration} for App Services, passed as props.
* @param appRef - A ref to the app instance, which can be used to access the app instance outside of the React component tree.
*/
export declare function AppProvider(props: DynamicAppProviderWithConfigurationProps): React.ReactNode;
/**
* React component providing a Realm App instance on the context for the
* sync hooks to use. An `AppProvider` is required for an app to use the hooks.
* @param app - The {@link Realm.App} for the provider.
*/
export declare function AppProvider(props: DynamicAppProviderWithAppProps): React.ReactNode;
/**
* Hook to access the current {@link Realm.App} from the {@link AppProvider} context.
* @throws if an AppProvider does not exist in the component’s ancestors
*/
export declare const useApp: <FunctionsFactoryType extends Realm.DefaultFunctionsFactory, CustomDataType extends Record<string, unknown>>() => Realm.App<FunctionsFactoryType, CustomDataType>;
export declare const useAuthResult: () => [import("./types").OperationResult, React.Dispatch<React.SetStateAction<import("./types").OperationResult>>];
export {};
//# sourceMappingURL=AppProvider.d.ts.map