grafana/public/app/features/playlist/usePlaylist.tsx
Hugo Häggmark 51e7b87f39
Playlist: Migrates New/Edit pages to React (#32218)
* WIP: initial commit

* Playlist: Migrates New/Edit to React

* Tests: adds tests for PlaylistForm

* Tests: adds more tests

* Chore: moved some styles

* Chore: updates after PR review
2021-03-23 07:45:04 +01:00

24 lines
630 B
TypeScript

import { useEffect, useState } from 'react';
import { Playlist } from './types';
import { getPlaylist } from './api';
export function usePlaylist(playlistId?: number) {
const [playlist, setPlaylist] = useState<Playlist>({ items: [], interval: '5m', name: '' });
const [loading, setLoading] = useState<boolean>(true);
useEffect(() => {
const initPlaylist = async () => {
if (!playlistId) {
setLoading(false);
return;
}
const list = await getPlaylist(playlistId);
setPlaylist(list);
setLoading(false);
};
initPlaylist();
}, []);
return { playlist, loading };
}