Skip to main content
Version: 1.0.5

AppShield

@spartanfx/react v1.0.5


@spartanfx/react / AppShield

Class: AppShield

Higher-order component that initializes and provides global application context to child components. Handles context population, error boundaries, debug logging, and loading state.

The component builds an IAppContext object that bundles:

the SPFx WebPartContext a ready‑to‑use PnP SPFI client user & group information a few quality‑of‑life helpers (try, log, report …)

Once initialised the context is exposed through React’s Context API:

const appContext: IAppContext = useAppContext();
ctx.sp.web.getList("/site/SiteAssets").items();

Under the hood <AppShield> also acts as:

an error boundary – (componentDidCatch) renders a friendly fallback UI when a descendant throws a loading gate – shows a modal spinner (or your own component) while the asynchronous initialisation runs

[!TIP] Because <AppShield> owns the global context you should place it as high as possible – ideally directly inside the web‑part’s root component.

Examples

<AppShield webPartContext={ctx} sp={sp}>
<Root />
</AppShield>
<AppShield
webPartContext={ctx}
sp={sp}
customContext={{ theme: "dark" }}
customLoadingComponent={<MySkeletonScreen />}
>
<Root />
</AppShield>

Extends