import {useEffect, useState} from "react";
import {apiAxios} from "../utils/Tools.js";

const countries = {}

export function useCountries(country = 'fr') {
    const [out, setOut] = useState(null)

    useEffect(() => {
        if (countries[country] === undefined) {
            apiAxios.get(`/countries/${country}/${country}`).then(data => {
                countries[country] = data.data
                setOut(data.data)
            })
        } else {
            setOut(countries[country])
        }
    }, [country]);


    return out;
}