plugin.tsx 550 B

1234567891011121314151617181920212223242526
  1. import useSWR, { SWRResponse } from 'swr';
  2. import { apiv3Get } from '~/client/util/apiv3-client';
  3. import { GrowiPluginHasId } from '~/interfaces/plugin';
  4. type Plugins = {
  5. plugins: GrowiPluginHasId[]
  6. }
  7. const pluginsFetcher = () => {
  8. return async() => {
  9. const reqUrl = '/plugins';
  10. try {
  11. const res = await apiv3Get(reqUrl);
  12. return res.data;
  13. }
  14. catch (err) {
  15. throw new Error(err);
  16. }
  17. };
  18. };
  19. export const useSWRxPlugins = (): SWRResponse<Plugins, Error> => {
  20. return useSWR('/plugins', pluginsFetcher());
  21. };