Służy do pobierania nazw wybranych utworów lub modlitw na podstawie identyfikatora playlisty.
import { useContext } from 'react';
import { PlaylistContext } from 'providers/PlaylistProvider';
import { ContentContext } from 'providers/ContentProvider';
const useNames = () => {
const { playlists } = useContext(PlaylistContext);
const { content } = useContext(ContentContext);
const getNames = (id) => {
let playlist = playlists.find((elem) => elem.id === id);
let names = [];
playlist.playlist.forEach((id) => {
if (id.slice(0, 4) === 'song')
names.push(content.songs.find((elem) => elem.id === Number(id.slice(6))).name);
else if (id.slice(0, 4) === 'pray')
names.push(content.prayers.find((elem) => elem.id === Number(id.slice(6))).name);
});
return names;
};
return {
getNames,
};
};
export default useNames;