@etsoo/smarterp-core
Version:
TypeScript APIs for SmartERP Core
40 lines (39 loc) • 1.07 kB
JavaScript
import { ReactAppContext } from "@etsoo/materialui";
import { useRequiredContext } from "@etsoo/react";
import React from "react";
import { PageDataContext } from "@etsoo/toolpad";
/**
* Get core service application context hook
* @returns Application
*/
export function useRequiredAppContext() {
// Get the app context
const app = useRequiredContext(ReactAppContext);
// Assume the app is core service app
return app;
}
export function usePageData(app, pageDataOrTitle, deps) {
const { dispatch } = React.useContext(PageDataContext);
React.useEffect(() => {
// Page title
dispatch(typeof pageDataOrTitle === "object"
? pageDataOrTitle
: { page: pageDataOrTitle });
return () => {
// Reset page data
dispatch(true);
app.pageExit();
};
}, deps);
}
/**
* Use page data empty
* @param app Application
*/
export function usePageDataEmpty(app) {
React.useEffect(() => {
return () => {
app.pageExit();
};
}, []);
}