Skip to content

Hooks Reference

Rebase provides React hooks to access framework functionality from any component within the <Rebase> provider tree.

The master hook — access everything:

import { useRebaseContext } from "@rebasepro/core";
function MyComponent() {
const context = useRebaseContext();
context.dataSource // Data operations
context.storageSource // File operations
context.authController // Auth state
context.navigation // Navigation state
context.sideEntityController // Side panel control
context.snackbarController // Toast notifications
}

Access authentication state:

import { useAuthController } from "@rebasepro/core";
function UserMenu() {
const auth = useAuthController();
auth.user // Current user (or null)
auth.initialLoading // Loading initial session
auth.signOut() // Log out
auth.getAuthToken() // Get JWT for API calls
auth.extra // Additional user data (roles, etc.)
}

Programmatically open entities in a side panel:

import { useSideEntityController } from "@rebasepro/core";
function OpenProductButton({ productId }) {
const sideEntityController = useSideEntityController();
return (
<button onClick={() => {
sideEntityController.open({
path: "products",
entityId: productId,
collection: productsCollection
});
}}>
Open Product
</button>
);
}

Methods:

MethodDescription
open({ path, entityId, collection })Open an entity in a side panel
close()Close the current side panel
replace({ path, entityId, collection })Replace the current side panel content

Show toast notifications:

import { useSnackbarController } from "@rebasepro/core";
function SaveButton() {
const snackbar = useSnackbarController();
const handleSave = async () => {
try {
await saveData();
snackbar.open({ type: "success", message: "Saved successfully!" });
} catch (error) {
snackbar.open({ type: "error", message: "Save failed" });
}
};
}

Access file storage operations:

import { useStorageSource } from "@rebasepro/core";
function FileUploader() {
const storage = useStorageSource();
const upload = async (file: File) => {
const result = await storage.uploadFile({
file,
fileName: file.name,
path: "documents"
});
const url = await storage.getDownloadURL(result.path);
return url;
};
}

Control light/dark theme:

import { useModeController } from "@rebasepro/core";
function ThemeToggle() {
const mode = useModeController();
return (
<button onClick={mode.toggleMode}>
Current: {mode.mode} {/* "light" | "dark" */}
</button>
);
}

Open a reference selection dialog:

import { useReferenceDialog } from "@rebasepro/core";
function SelectProduct() {
const referenceDialog = useReferenceDialog({
path: "products",
collection: productsCollection,
onSingleEntitySelected: (entity) => {
console.log("Selected:", entity);
}
});
return <button onClick={referenceDialog.open}>Select Product</button>;
}

Access navigation state and resolved collections:

import { useNavigationController } from "@rebasepro/core";
function MyComponent() {
const navigation = useNavigationController();
navigation.collections // All registered collections
navigation.views // Custom views
navigation.adminViews // Admin-mode views
navigation.getCollection(path) // Get collection for a path
}