The package exports 7 hooks for building custom logging interfaces. These hooks power the built-in components and can be used directly for custom implementations.
useSessionList
Hook for managing session list state with pagination, sorting, and filtering. Wraps usePaginatedData with session-specific configuration.
import { useSessionList } from "@millerbyte/react-logging";
const SessionsPage = () => {
const {
rows,
totalCount,
pageIndex,
pageSize,
setPageIndex,
setPageSize,
sorting,
setSorting,
filters,
setFilters,
isLoading,
error
} = useSessionList({
fetchSessions: loggingClient.fetchSessions,
enablePolling: true,
pollingInterval: 15000,
});
// Build custom UI with the data
};Options
| Option | Type | Description |
|---|---|---|
sessions | TInput[] | Client mode: pass data array |
fetchSessions | (params) => Promise | Server mode: fetch function |
dataAdapter | DataAdapter | Transform raw data to DTOs |
initialPageSize | number | Default page size (10) |
initialFilters | FilterState | Initial filter values |
enablePolling | boolean | Enable auto-refresh |
pollingInterval | number | Polling interval (ms) |
onDataDelta | (prev, next) => void | Callback when data changes |
Return Value
| Property | Type | Description |
|---|---|---|
rows | LoginSessionDto[] | Current page data |
totalCount | number | Total items across all pages |
pageIndex | number | Current page (0-indexed) |
pageSize | number | Items per page |
pageCount | number | Total pages |
setPageIndex | (n) => void | Change page |
setPageSize | (n) => void | Change page size |
sorting | SortingState | Current sort state |
setSorting | (s) => void | Update sorting |
filters | FilterState | Current filters |
setFilters | (f) => void | Update filters |
isLoading | boolean | Loading state |
error | unknown | Error state |
isServerMode | boolean | Whether using fetch function |
useActionList
Same API as useSessionList but for API actions. Uses actionsand fetchActions props.
const { rows, isLoading } = useActionList({
fetchActions: loggingClient.fetchActions,
});useUserList
Hook for managing user analytics list state with pagination, sorting, and filtering. Returns aggregated UserSummaryDto items. Added in v0.1.6.
import { useUserList } from "@millerbyte/react-logging";
const UsersPage = () => {
const {
rows,
totalCount,
pageIndex,
pageSize,
setPageIndex,
setPageSize,
sorting,
setSorting,
filters,
setFilters,
isLoading,
error
} = useUserList({
fetchUsers: loggingClient.fetchUsers,
enablePolling: true,
pollingInterval: 30000,
});
// Build custom user analytics UI
};Options
| Option | Type | Description |
|---|---|---|
users | TInput[] | Client mode: pass data array |
fetchUsers | (params) => Promise | Server mode: fetch function |
dataAdapter | DataAdapter | Transform raw data to DTOs |
initialPageSize | number | Default page size (10) |
initialFilters | FilterState | Initial filter values |
enablePolling | boolean | Enable auto-refresh |
pollingInterval | number | Polling interval (ms) |
onDataDelta | (prev, next) => void | Callback when data changes |
Return Value
| Property | Type | Description |
|---|---|---|
rows | UserSummaryDto[] | Current page data |
totalCount | number | Total items across all pages |
pageIndex | number | Current page (0-indexed) |
pageSize | number | Items per page |
pageCount | number | Total pages |
setPageIndex | (n) => void | Change page |
setPageSize | (n) => void | Change page size |
sorting | SortingState | Current sort state |
setSorting | (s) => void | Update sorting |
filters | FilterState | Current filters |
setFilters | (f) => void | Update filters |
isLoading | boolean | Loading state |
error | unknown | Error state |
isServerMode | boolean | Whether using fetch function |
usePaginatedData
Generic pagination hook used internally by useSessionList, useActionList, and useUserList. Use directly for custom data types.
import { usePaginatedData } from "@millerbyte/react-logging";
const { rows, setPageIndex } = usePaginatedData({
queryKey: "my-custom-data",
fetchPage: fetchMyData,
adapter: myDataAdapter,
});useFilters
Manages filter state with utilities for updating and resetting.
import { useFilters } from "@millerbyte/react-logging";
const { filters, updateFilters, resetFilters, hasFilters } = useFilters({
userId: "user123",
isActive: true,
});
// Update a single filter
updateFilters({ statusCodes: [200, 201] });
// Reset all filters
resetFilters();
// Check if any filters are active
if (hasFilters) {
showClearButton();
}Return Value
| Property | Type | Description |
|---|---|---|
filters | FilterState | Current filter values |
setFilters | (f) => void | Replace all filters |
updateFilters | (partial) => void | Merge partial filter updates |
resetFilters | () => void | Reset to initial state |
hasFilters | boolean | True if any filter is set |
useRealTimeUpdates
Tracks data changes between polls and triggers callbacks when data differs. Useful for notifications or highlighting new items.
import { useRealTimeUpdates } from "@millerbyte/react-logging";
useRealTimeUpdates({
enabled: true,
data: sessions,
onDataDelta: (previous, next) => {
const newSessions = next.filter(
s => !previous.some(p => p.Id === s.Id)
);
if (newSessions.length > 0) {
showNotification(`${newSessions.length} new sessions`);
}
},
});useDebouncedValue
Debounces a value for use in search inputs or filter updates.
import { useDebouncedValue } from "@millerbyte/react-logging";
const [searchInput, setSearchInput] = useState("");
const debouncedSearch = useDebouncedValue(searchInput, 300);
// Use debouncedSearch for API calls
useEffect(() => {
fetchResults(debouncedSearch);
}, [debouncedSearch]);