Parafia Skoczów
  • 👋Witaj w Parafii Skoczów
  • O APLIKACJI
    • ✨Funkcjonalności
    • 📷Galeria
    • 🛠️Zarządzanie treściami
  • DLA PROGRAMISTÓW
    • 🏗️Przegląd narzędzi
    • ⛪Parafia Skoczów
      • Assets
      • Components
        • Atoms
        • Molecules
        • Organisms
        • Templates
      • Helpers
        • getAnimationProps
        • getData
        • getTransmissionUrl
        • searchContent
        • useModal
      • Hooks
        • useDisablePinchZoom
        • usePinching
        • useSwipe
      • Providers
        • ContentProvider
        • FirebaseProvider
        • PlaylistProvider
      • Utils
      • Views
        • Home
        • Categories
        • Titles
        • Text
        • Playlist
        • Search
      • Cordova
      • Rozwiązywanie problemów
    • 🎶Playlist Maker
      • Assets
      • Components
        • Atoms
        • Molecules
        • Organisms
        • Templates
      • Helpers
      • Hooks
        • useDnd
        • useEdit
        • useName
        • useModal
      • Providers
        • ContentProvider
        • FirebaseProvider
        • NotificationProvider
        • PlaylistProvider
      • Utils
      • Cordova
      • Rozwiązywanie problemów
Powered by GitBook
On this page
  1. DLA PROGRAMISTÓW
  2. Parafia Skoczów
  3. Helpers

getData

Funkcja pobiera kontent, przyjmując adresy URL do danych, funkcję zmieniającą stan aplikacji oraz funkcję, która pozwala ustawić błąd. Otrzymane dane są natychmiastowo sortowane alfabetycznie.

getData.js
import axios from 'axios';

const sortData = (data) => {
  return data[0] ? data.sort((a, b) => a.name.localeCompare(b.name)) : data;
};

export const getData = async (queries, dispatch, setError) => {
  const values = Object.values(queries);
  const keys = Object.keys(queries);
  const promises = values.map((link) => axios.get(link));

  try {
    const res = await Promise.all(promises);
    res.forEach((data, index) => {
      dispatch({
        field: keys[index],
        value: sortData(data.data),
      });
    });
  } catch {
    setError(`Błąd połączenia z internetem`);
  }
};
PreviousgetAnimationPropsNextgetTransmissionUrl

Last updated 1 year ago

⛪