src/js/hooks: add useSurah.ts
This commit is contained in:
parent
34cd6129e8
commit
9b53401092
1 changed files with 18 additions and 0 deletions
18
src/js/hooks/useSurah.ts
Normal file
18
src/js/hooks/useSurah.ts
Normal 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];
|
||||
}
|
Loading…
Reference in a new issue