Hooks-Referenz
Übersicht
Abschnitt betitelt „Übersicht“Rebase stellt React-Hooks bereit, um von jeder Komponente innerhalb des <Rebase> Provider-Baums auf Framework-Funktionen zuzugreifen.
useRebaseContext
Abschnitt betitelt „useRebaseContext“Der Master-Hook – Zugriff auf alles:
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}useAuthController
Abschnitt betitelt „useAuthController“Zugriff auf den Authentifizierungszustand:
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.)}useSideEntityController
Abschnitt betitelt „useSideEntityController“Entitäten programmatisch in einem Seitenfenster öffnen:
import { useSideEntityController } from "@rebasepro/core";
function OpenProductButton({ productId }) { const sideEntityController = useSideEntityController();
return ( <button onClick={() => { sideEntityController.open({ path: "products", entityId: productId, collection: productsCollection }); }}> Produkt öffnen </button> );}Methoden:
| Methode | Beschreibung |
|---|---|
open({ path, entityId, collection }) | Eine Entität in einem Seitenfenster öffnen |
close() | Das aktuelle Seitenfenster schließen |
replace({ path, entityId, collection }) | Den Inhalt des aktuellen Seitenfensters ersetzen |
useSnackbarController
Abschnitt betitelt „useSnackbarController“Toast-Benachrichtigungen anzeigen:
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" }); } };}useStorageSource
Abschnitt betitelt „useStorageSource“Zugriff auf Dateispeicheroperationen:
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; };}useModeController
Abschnitt betitelt „useModeController“Hell-/Dunkel-Thema steuern:
import { useModeController } from "@rebasepro/core";
function ThemeToggle() { const mode = useModeController();
return ( <button onClick={mode.toggleMode}> Aktuell: {mode.mode} {/* "light" | "dark" */} </button> );}useEntitySelectionDialog
Abschnitt betitelt „useEntitySelectionDialog“Öffnen eines Seitendialogs zur Auswahl von Entitäten aus einer Sammlung. Dies ist derselbe Hook, der intern verwendet wird, wenn eine Relationseigenschaft gerendert wird:
import { useEntitySelectionDialog } from "@rebasepro/core";
function SelectProduct() { const selectionDialog = useEntitySelectionDialog({ path: "products", collection: productsCollection, onSingleEntitySelected: (entity) => { console.log("Selected:", entity); } });
return <button onClick={selectionDialog.open}>Produkt auswählen</button>;}useNavigationController
Abschnitt betitelt „useNavigationController“Zugriff auf Navigationszustand und aufgelöste Sammlungen:
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}Nächste Schritte
Abschnitt betitelt „Nächste Schritte“- Frontend-Übersicht — React-Framework-Referenz
- Client SDK — SDK für Datenoperationen