import { Account, AccountClass, AnonymousJazzAgent, AnyAccountSchema, CoValue, CoValueClassOrSchema, ExportedCoValue, JazzContextManager, Loaded, MaybeLoaded, ResolveQuery, ResolveQueryStrict, SchemaResolveQuery, type BranchDefinition, type CoValueCursor } from "jazz-tools"; import { CoValueSubscription } from "./types.js"; export declare function useJazzContext(): JazzContextManager; export declare function useJazzContextValue(): import("jazz-tools").JazzContextType; export declare function useAuthSecretStorage(): import("jazz-tools").AuthSecretStorage; export declare function useIsAuthenticated(): boolean; export declare function useCoValueSubscription = SchemaResolveQuery>(Schema: S, id: string | undefined | null, options?: { resolve?: ResolveQueryStrict; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }, source?: string): CoValueSubscription | null; /** * React hook for subscribing to CoValues and handling loading states. * * This hook provides a convenient way to subscribe to CoValues and automatically * handles the subscription lifecycle (subscribe on mount, unsubscribe on unmount). * It also supports deep loading of nested CoValues through resolve queries. * * The {@param options.select} function allows returning only specific parts of the CoValue data, * which helps reduce unnecessary re-renders by narrowing down the returned data. * Additionally, you can provide a custom {@param options.equalityFn} to further optimize * performance by controlling when the component should re-render based on the selected data. * * @returns The loaded CoValue, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state. * If a selector function is provided, returns the result of the selector function. * * @example * ```tsx * // Select only specific fields to reduce re-renders * const Project = co.map({ * name: z.string(), * description: z.string(), * tasks: co.list(Task), * lastModified: z.date(), * }); * * function ProjectTitle({ projectId }: { projectId: string }) { * // Only re-render when the project name changes, not other fields * const projectName = useCoState( * Project, * projectId, * { * select: (project) => !project.$isLoading ? project.name : "Loading...", * } * ); * * return

{projectName}

; * } * ``` * * @example * ```tsx * // Deep loading with resolve queries * const Project = co.map({ * name: z.string(), * tasks: co.list(Task), * owner: TeamMember, * }); * * function ProjectView({ projectId }: { projectId: string }) { * const project = useCoState(Project, projectId, { * resolve: { * tasks: { $each: true }, * owner: true, * }, * }); * * if (!project.$isLoaded) { * switch (project.$jazz.loadingState) { * case "unauthorized": * return "Project not accessible"; * case "unavailable": * return "Project not found"; * case "loading": * return "Loading project..."; * } * } * * return ( *
*

{project.name}

*

Owner: {project.owner.name}

*
    * {project.tasks.map((task) => ( *
  • {task.title}
  • * ))} *
*
* ); * } * ``` * * @example * ```tsx * // Using with optional references and error handling * const Task = co.map({ * title: z.string(), * assignee: co.optional(TeamMember), * subtasks: co.list(Task), * }); * * function TaskDetail({ taskId }: { taskId: string }) { * const task = useCoState(Task, taskId, { * resolve: { * assignee: true, * subtasks: { $each: { $onError: 'catch' } }, * }, * }); * * if (!task.$isLoaded) { * switch (task.$jazz.loadingState) { * case "unauthorized": * return "Task not accessible"; * case "unavailable": * return "Task not found"; * case "loading": * return "Loading task..."; * } * } * * return ( *
*

{task.title}

* {task.assignee &&

Assigned to: {task.assignee.name}

} *
    * {task.subtasks.map((subtask, index) => ( * subtask.$isLoaded ?
  • {subtask.title}
  • :
  • Inaccessible subtask
  • * ))} *
*
* ); * } * ``` * * @example * ```tsx * // Use custom equality function for complex data structures * const TaskList = co.list(Task); * * function TaskCount({ listId }: { listId: string }) { * const taskStats = useCoState( * TaskList, * listId, * { * resolve: { $each: true }, * select: (tasks) => { * if (!tasks.$isLoaded) return { total: 0, completed: 0 }; * return { * total: tasks.length, * completed: tasks.filter(task => task.completed).length, * }; * }, * // Custom equality to prevent re-renders when stats haven't changed * equalityFn: (a, b) => a.total === b.total && a.completed === b.completed, * } * ); * * return ( *
* {taskStats.completed} of {taskStats.total} tasks completed *
* ); * } * ``` * * For more examples, see the [subscription and deep loading](https://jazz.tools/docs/react/using-covalues/subscription-and-loading) documentation. */ export declare function useCoState = SchemaResolveQuery, TSelectorReturn = MaybeLoaded>>( /** The CoValue schema or class constructor */ Schema: S, /** The ID of the CoValue to subscribe to. If `undefined`, returns an `unavailable` value */ id: string | undefined, /** Optional configuration for the subscription */ options?: { /** Resolve query to specify which nested CoValues to load */ resolve?: ResolveQueryStrict; /** Select which value to return */ select?: (value: MaybeLoaded>) => TSelectorReturn; /** Equality function to determine if the selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; preloaded?: ExportedCoValue>; }): TSelectorReturn; export declare function useSuspenseCoState = SchemaResolveQuery, TSelectorReturn = Loaded>( /** The CoValue schema or class constructor */ Schema: S, /** The ID of the CoValue to subscribe to */ id: string, /** Optional configuration for the subscription */ options?: { /** Resolve query to specify which nested CoValues to load */ resolve?: ResolveQueryStrict; /** Select which value to return */ select?: (value: Loaded) => TSelectorReturn; /** Equality function to determine if the selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; preloaded?: ExportedCoValue>; }): TSelectorReturn; /** * Returns a subscription's current value. * Allows to optionally select a subset of the subscription's value. * * This is the single-value counterpart to {@link useSubscriptionsSelector}. * Keeping it separate for performance reasons. */ export declare function useSubscriptionSelector = SchemaResolveQuery, TSelectorInput = MaybeLoaded>, TSelectorReturn = TSelectorInput>(subscription: CoValueSubscription, options?: { select?: (value: TSelectorInput) => TSelectorReturn; equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; }): TSelectorReturn; export declare function useAccountSubscription | AnyAccountSchema, const R extends ResolveQuery = SchemaResolveQuery>(Schema: S, options?: { resolve?: ResolveQueryStrict; unstable_branch?: BranchDefinition; cursor?: CoValueCursor; }, source?: string): CoValueSubscription; /** * React hook for accessing the current user's account. * * This hook provides access to the current user's account profile and root data. * It automatically handles the subscription lifecycle and supports deep loading of nested * CoValues through resolve queries. * * The {@param options.select} function allows returning only specific parts of the account data, * which helps reduce unnecessary re-renders by narrowing down the returned data. * Additionally, you can provide a custom {@param options.equalityFn} to further optimize * performance by controlling when the component should re-render based on the selected data. * * @returns The account data, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state. * If a selector function is provided, returns the result of the selector function. * * @example * ```tsx * // Select only specific fields to reduce re-renders * const MyAppAccount = co.account({ * profile: co.profile(), * root: co.map({ * name: z.string(), * email: z.string(), * lastLogin: z.date(), * }), * }); * * function UserProfile({ accountId }: { accountId: string }) { * // Only re-render when the profile name changes, not other fields * const profileName = useAccount( * MyAppAccount, * { * resolve: { * profile: true, * root: true, * }, * select: (account) => account.$isLoaded ? account.profile.name : "Loading...", * } * ); * * return

{profileName}

; * } * ``` * * @example * ```tsx * // Deep loading with resolve queries * function ProjectListWithDetails() { * const me = useAccount(MyAppAccount, { * resolve: { * profile: true, * root: { * myProjects: { * $each: { * tasks: true, * }, * }, * }, * }, * }); * * if (!me.$isLoaded) { * switch (me.$jazz.loadingState) { * case "unauthorized": * return "Account not accessible"; * case "unavailable": * return "Account not found"; * case "loading": * return "Loading account..."; * } * } * * return ( *
*

{me.profile.name}'s projects

*
    * {me.root.myProjects.map((project) => ( *
  • * {project.name} ({project.tasks.length} tasks) *
  • * ))} *
*
* ); * } * ``` * */ export declare function useAccount | AnyAccountSchema, const R extends ResolveQuery = SchemaResolveQuery, TSelectorReturn = MaybeLoaded>>( /** The account schema to use. Defaults to the base Account schema */ AccountSchema?: A, /** Optional configuration for the subscription */ options?: { /** Resolve query to specify which nested CoValues to load from the account */ resolve?: ResolveQueryStrict; /** Select which value to return from the account data */ select?: (account: MaybeLoaded>) => TSelectorReturn; /** Equality function to determine if the selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; }): TSelectorReturn; export declare function useSuspenseAccount | AnyAccountSchema, const R extends ResolveQuery = SchemaResolveQuery, TSelectorReturn = Loaded>( /** The account schema to use. Defaults to the base Account schema */ AccountSchema?: A, /** Optional configuration for the subscription */ options?: { /** Resolve query to specify which nested CoValues to load from the account */ resolve?: ResolveQueryStrict; /** Select which value to return from the account data */ select?: (account: Loaded) => TSelectorReturn; /** Equality function to determine if the selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; }): TSelectorReturn; /** * Returns a function for logging out of the current account. */ export declare function useLogOut(): () => void; /** * React hook for accessing the current agent. An agent can either be: * - an Authenticated Account, if the user is logged in * - an Anonymous Account, if the user didn't log in * - or an anonymous agent, if in guest mode * * The agent can be used as the `loadAs` parameter for load and subscribe methods. */ export declare function useAgent | AnyAccountSchema = typeof Account>(): AnonymousJazzAgent | Loaded; export declare function experimental_useInboxSender(inboxOwnerID: string | undefined): (message: I) => Promise; /** * Hook that returns the current connection status to the Jazz sync server. * * @returns `true` when connected to the server, `false` when disconnected * * @remarks * On connection drop, this hook will return `false` only when Jazz detects the disconnection * after 5 seconds of not receiving a ping from the server. */ export declare function useSyncConnectionStatus(): boolean; /** * Subscribe to multiple CoValues with unified Suspense handling. * * This hook accepts a list of CoValue IDs and returns an array of loaded values, * suspending until all values are available. * * @param Schema - The CoValue schema or class constructor * @param ids - Array of CoValue IDs to subscribe to * @param options - Optional configuration, including resolve query * @returns An array of loaded CoValues in the same order as the input IDs */ export declare function useSuspenseCoStates = SchemaResolveQuery, TSelectorReturn = Loaded>(Schema: S, ids: readonly string[], options?: { /** Resolve query to specify which nested CoValues to load */ resolve?: ResolveQueryStrict; /** Select which value to return. Applies to each element individually. */ select?: (value: Loaded) => TSelectorReturn; /** Equality function to determine if a selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; }): TSelectorReturn[]; /** * Subscribe to multiple CoValues without Suspense. * * This hook accepts a list of CoValue IDs and returns an array of maybe-loaded values. * Unlike `useSuspenseCoStates`, this hook does not suspend and returns loading/unavailable * states that can be checked via the `$isLoaded` property. * * @param Schema - The CoValue schema or class constructor * @param ids - Array of CoValue IDs to subscribe to * @param options - Optional configuration, including resolve query * @returns An array of MaybeLoaded CoValues in the same order as the input IDs * * @example * ```typescript * const [project1, project2] = useCoStates( * ProjectSchema, * [projectId1, projectId2], * { resolve: { assignee: true } } * ); * * if (!project1.$isLoaded || !project2.$isLoaded) { * return ; * } * ``` */ export declare function useCoStates = SchemaResolveQuery, TSelectorReturn = MaybeLoaded>>(Schema: S, ids: readonly string[], options?: { /** Resolve query to specify which nested CoValues to load */ resolve?: ResolveQueryStrict; /** Select which value to return. Applies to each element individually. */ select?: (value: MaybeLoaded>) => TSelectorReturn; /** Equality function to determine if a selected value has changed, defaults to `Object.is` */ equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean; /** * Create or load a branch for isolated editing. * * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version. * It's a fork of your data graph: the same schema, but with diverging values. * * The checkout of the branch is applied on all the resolved values. * * @param name - A unique name for the branch. This identifies the branch * and can be used to switch between different branches of the same CoValue. * @param owner - The owner of the branch. Determines who can access and modify * the branch. If not provided, the branch is owned by the current user. * * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation. */ unstable_branch?: BranchDefinition; /** * Load the CoValue at a specific cursor. * * Cursors let you take a "snapshot" of a CoValue at the time of cursor creations. */ cursor?: CoValueCursor; }): TSelectorReturn[]; //# sourceMappingURL=hooks.d.ts.map