Aller au contenu principal

AppProvider Component

Description

The AppProvider is a context provider that manages global state for the Liberty Framework. It provides access to:

  • Authentication state
  • Application properties
  • User properties
  • Module configurations
  • Snack messages
  • WebSocket handling

This provider allows injecting custom functions for retrieving data such as applications, users, tokens, and menus.

Props

PropTypeDefaultDescription
childrenReactNode-Components wrapped by the provider.
useAuth() => AuthContextProps-Custom authentication hook.
getModules() => Promise<IModulesProps>-Fetch function for modules configuration.
getApplications() => Promise<IAppsProps>-Fetch function for application settings.
getUser() => Promise<IUsersProps>-Fetch function for user details.
getMenus() => Promise<IMenusProps>-Fetch function for application menus.

Example Usage

import { AppProvider, useAppContext } from "@nomana-it/liberty-core"

export const AppProviderExample = () => {
return (
<AppProvider>
<MyApp />
</AppProvider>
);
};

const MyApp = () => {
const { userProperties, modulesProperties } = useAppContext();

return (
<div>
<h2>User: {userProperties.name}</h2>
<p>Debug Mode: {modulesProperties.debug.enabled ? "Enabled" : "Disabled"}</p>
</div>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core