Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created March 7, 2022 19:30
Show Gist options
  • Save larkintuckerllc/9a5cba1fbc104ccaa27f6a6316280ab9 to your computer and use it in GitHub Desktop.
Save larkintuckerllc/9a5cba1fbc104ccaa27f6a6316280ab9 to your computer and use it in GitHub Desktop.
import { useEffect, useState } from 'react';
import { useApi } from '@backstage/core-plugin-api';
import { myPluginApiRef } from '../api/types';
export const useMyPluginObjects = () => {
const [loading, setLoading] = useState<boolean>(true);
const [status, setStatus] = useState<string>('');
const [error, setError] = useState<boolean>(false);
const myPluginApi = useApi(myPluginApiRef);
const getObjects = async () => {
try {
const health = await myPluginApi.getHealth();
setStatus(health.status);
} catch (e) {
setError(true);
} finally {
setLoading(false);
}
}
useEffect(() => {
getObjects();
});
return {
error,
loading,
status,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment