src/js/hooks: add useSurah.ts

This commit is contained in:
0x1eef 2022-10-31 05:41:14 -03:00
parent 34cd6129e8
commit 9b53401092

18
src/js/hooks/useSurah.ts Normal file
View file

@ -0,0 +1,18 @@
import { useState, useEffect } from "react";
import { Quran } from "lib/Quran";
export default function(locale: string, surahByNumber: number) {
const [loading, setLoading] = useState(true);
const [surah, setSurah] = useState(null);
useEffect(() => {
(async () => {
const res = await fetch(`/json/${locale}/${surahByNumber}.json`);
const json = await res.json();
setLoading(false);
setSurah(Quran.Surah.fromJSON(json.shift(), json));
})();
}, []);
return [loading, surah];
}