useVideoCategoryOptions.ts 917 B

123456789101112131415161718192021222324252627282930313233
  1. import { useState, useEffect } from 'react';
  2. import { getVideoContentCategoryListApi } from '@src/http/api';
  3. import request from '@src/http/index';
  4. export const useVideoCategoryOptions = () => {
  5. const [videoCategoryOptions, setVideoCategoryOptions] = useState<string[]>([]);
  6. const [loading, setLoading] = useState(false);
  7. const [error, setError] = useState<string | null>(null);
  8. const getVideoCategoryList = async () => {
  9. try {
  10. setLoading(true);
  11. setError(null);
  12. const data = await request.get(getVideoContentCategoryListApi);
  13. setVideoCategoryOptions(data.data as string[]);
  14. } catch (err) {
  15. setError(err instanceof Error ? err.message : 'Failed to fetch accounts');
  16. } finally {
  17. setLoading(false);
  18. }
  19. };
  20. useEffect(() => {
  21. getVideoCategoryList();
  22. }, []);
  23. return {
  24. videoCategoryOptions,
  25. getVideoCategoryList,
  26. loading,
  27. error
  28. };
  29. };