This directory contains React hooks for the DataManager library, following modern React patterns with TanStack Query for data fetching.
useActionsA hook for fetching available actions from the DataManager API using TanStack Query.
import { useActions } from "../hooks/useActions";
function ActionsDropdown({ projectId }) {
const {
actions,
isLoading,
isError,
error,
refetch,
isFetching,
} = useActions({
projectId, // Optional: Used for cache scoping per project
enabled: isOpen, // Only fetch when dropdown is opened
staleTime: 5 * 60 * 1000, // Optional: 5 minutes
cacheTime: 10 * 60 * 1000, // Optional: 10 minutes
});
if (isLoading) return <div>Loading...</div>;
if (isError) return <div>Error: {error.message}</div>;
return (
<div>
{actions.map((action) => (
<button key={action.id}>{action.title}</button>
))}
</div>
);
}
options.projectId (string, optional): Project ID for scoping the query cache. When provided, actions are cached per project, preventing cache conflicts in multi-project scenariosoptions.enabled (boolean, default: true): Whether to enable the queryoptions.staleTime (number, default: 5 * 60 * 1000): Time in ms before data is considered staleoptions.cacheTime (number, default: 10 * 60 * 1000): Time in ms before unused data is garbage collectedactions (Action[]): Array of available actionsisLoading (boolean): True on first loadisFetching (boolean): True whenever data is being fetchedisError (boolean): True if the query failederror (Error): The error object if query failedrefetch (function): Function to manually refetch the datauseDataManagerUsersA hook for fetching users from the DataManager API with infinite pagination support.
See useUsers.ts for documentation.
useFirstMountState: Utility hook to detect first mountuseUpdateEffect: Effect hook that skips the first renderThe DataManager is gradually migrating from MobX State Tree flows to TanStack Query hooks for better performance, caching, and developer experience.
The hooks replace the need for MobX flows for data fetching:
store.fetchActions() is now deprecated but kept for backward compatibilityuseActions() hookuseActions hook, preventing duplicate API callsBefore (MobX):
useEffect(() => {
if (isOpen && actions.length === 0) {
setIsLoading(true);
store.fetchActions().finally(() => {
setIsLoading(false);
});
}
}, [isOpen, actions.length, store]);
After (TanStack Query):
const { actions, isLoading, isFetching } = useActions({
projectId, // Optional: for cache scoping
enabled: isOpen,
});
enabled: false for data that's not immediately neededprojectId when working with project-specific data to prevent cache conflictsstaleTime and cacheTime based on data freshness requirementsThe QueryClient is configured at the app level in App.tsx:
import { QueryClientProvider } from "@tanstack/react-query";
import { queryClient } from "@humansignal/core/lib/utils/query-client";
<QueryClientProvider client={queryClient}>
<Provider store={app}>
{/* App content */}
</Provider>
</QueryClientProvider>
This ensures all hooks have access to the shared query cache.