text: import { useEffect, useContext } from "react";
  import { EmployeeContext } from "../components/EmployeeContext";
  import axios from "axios";
  
  export function useGet(url) {
    const {
      employees,
      setEmployees,
      displayedEmployees,
      setDisplayedEmployees
    } = useContext(EmployeeContext);
  
    // gets employees from an api, stores them in both employees, and displayed employees. Only occurs once when component is mounted.
    useEffect(() => {
      async function getEmployees() {
        try {
          const response = await axios.get(url);
          // using employees to store a copy of all the employees that will not be manipulated
          setEmployees(response.data.results);
          // using displayed employees to be a manipulated version of the employees that will be displayed for sorting and filtering.
          setDisplayedEmployees(response.data.results);
        } catch (error) {
          console.log("error ocurred getting info from the API: ", error);
        }
      }
      getEmployees();
      //line below ignores empty array error
      // eslint-disable-next-line
    }, []);
  
    // used to decide which sort function to trigger
    function sortFunc(sort) {
      switch (sort) {
        case "name":
          sortByName();
          break;
        case "age":
          sortByAge();
          break;
        default:
          console.log("sort does not match any cases");
      }
    }
  
    // sorts the employees based on first name.
    function sortByName() {
      employees.sort(function(a, b) {
        if (a.name.first < b.name.first) {
          return -1;
        } else {
          return 1;
        }
      });
      setDisplayedEmployees([...employees]);
    }
  
    // sorts the employees based on age.
    function sortByAge() {
      employees.sort(function(a, b) {
        return a.dob.age - b.dob.age;
      });
      setDisplayedEmployees([...employees]);
    }
  
    return { displayedEmployees, sortFunc };
  }
  