Object containing the CIA content service, loading state, error state, and refresh function
// Basic usage with loading and error handling
function MyComponent() {
const { ciaContentService, isLoading, error, refresh } = useCIAContentService();
if (isLoading) {
return <div>Loading CIA content service...</div>;
}
if (error) {
return (
<div>
<p>Error: {error.message}</p>
<button onClick={refresh}>Retry</button>
</div>
);
}
if (!ciaContentService) {
return <div>Service not available</div>;
}
// Safe to use the service here
const availabilityDetails = ciaContentService.getCIADetails('availability', 'High');
return <div>{availabilityDetails.description}</div>;
}
// Advanced usage with multiple service calls
function SecurityDashboard() {
const { ciaContentService, isLoading, error } = useCIAContentService();
const [selectedLevel, setSelectedLevel] = useState<SecurityLevel>('Moderate');
if (isLoading || !ciaContentService) {
return <LoadingSpinner />;
}
if (error) {
return <ErrorBoundary error={error} />;
}
const availDetails = ciaContentService.getCIADetails('availability', selectedLevel);
const integrityDetails = ciaContentService.getCIADetails('integrity', selectedLevel);
const confDetails = ciaContentService.getCIADetails('confidentiality', selectedLevel);
return (
<div>
<h2>Security Level: {selectedLevel}</h2>
<ComponentCard title="Availability" details={availDetails} />
<ComponentCard title="Integrity" details={integrityDetails} />
<ComponentCard title="Confidentiality" details={confDetails} />
</div>
);
}
Custom hook to access the CIA content service with loading and error states
Provides a convenient way to access the CIAContentService in React components with automatic initialization, loading states, and error handling. The service is initialized once when the component mounts and can be refreshed on demand.
Features
Usage Guidelines
isLoadingbefore rendering contenterrorstate to provide user feedbackciaContentServiceis not null before userefresh()to retry after errors