import { useState,useEffect } from "react";

export const useAsyncState =(initialValue:any) =>{
    const [value, setValue] = useState(initialValue);
    const setter = (x:any) =>
      new Promise(resolve => {
        setValue(x);
        resolve(x);
      });
    return [value, setter];
}


export function useMediaQuery(query:string) {
  const [matches, setMatches] = useState(false);

  useEffect(() => {
    const media = window.matchMedia(query);
    if (media.matches !== matches) {
      setMatches(media.matches);
    }
    const listener = () => {
      setMatches(media.matches);
    };
    media.addListener(listener);
    return () => media.removeListener(listener);
  }, [matches, query]);

  return matches;
}