Zakat calculators are a nice small project: a bit of state, a bit of math, and some real-world concerns like offline use, number formatting and right-to-left text. In this tutorial we build one in React, using the Zakat API from QuraniAPI as the data source.
Important: this is a coding tutorial, not a religious ruling. Please confirm rulings and your personal calculation with a qualified scholar.
What the API gives us
The Zakat endpoint is documented on its API page and in the docs. The slug is zakat and the request looks like this:
GET https://quranicapi.online/api/serve.php?slug=zakat&lang=en Use lang=all for all 9 languages, or a code such as en, ur, fr, de, ru, tr, ms, zh-CN or ja. The sample response I saw on the page contains:
- zakat_rate: 2.5
- nisab: an array with entries for gold (87.48 grams, 7.5 tola) and silver (612.36 grams, 52.5 tola), each with a translations object
- items: guideline entries with a category (for example cash) and a translation string
It is listed as a premium API. Check the pricing page for plans (at the time of writing: $20/mo, $100/yr, or a $900 one-time full dataset). The docs say to request a key; check the docs page for the exact way to send it, since I won't guess at it here.
Step 1: a local sample (offline-first)
Because the live response may need a key, we ship a clearly labelled local sample that copies the shape above. If the network fails, the app still works.
// zakatSample.js -- LOCAL SAMPLE copied from the public sample JSON. // Check the docs page for the exact live response. export const ZAKAT_SAMPLE = { zakat_rate: 2.5, nisab: [ { type: "gold", unit: "grams", value: 87.48, tola: 7.5 }, { type: "silver", unit: "grams", value: 612.36, tola: 52.5 }, ], }; Step 2: a fetch helper with a cache
// zakatApi.js import { ZAKAT_SAMPLE } from "./zakatSample"; const URL = "https://quranicapi.online/api/serve.php?slug=zakat&lang=en"; const KEY = "zakat-cache-v1"; export async function loadZakat() { try { const res = await fetch(URL); if (!res.ok) throw new Error("HTTP " + res.status); const data = await res.json(); localStorage.setItem(KEY, JSON.stringify(data)); return { data, source: "live" }; } catch (e) { const cached = localStorage.getItem(KEY); if (cached) return { data: JSON.parse(cached), source: "cache" }; return { data: ZAKAT_SAMPLE, source: "sample" }; } } Order of preference: live, then last cached response, then the bundled sample. Showing the source to the user keeps things honest.
Step 3: the React component
The calculator does one simple thing: it takes a total of zakatable wealth, compares it to a nisab amount the user supplies in their currency, and multiplies by the rate from the API. Converting grams of gold or silver into currency needs a price that this API does not provide, so the user enters the current nisab value themselves.
import { useEffect, useMemo, useState } from "react"; import { loadZakat } from "./zakatApi"; export default function ZakatCalculator({ locale = "en", currency = "USD" }) { const [info, setInfo] = useState(null); const [wealth, setWealth] = useState(""); const [nisabValue, setNisabValue] = useState(""); useEffect(() => { loadZakat().then(setInfo); }, []); const fmt = useMemo( () => new Intl.NumberFormat(locale, { style: "currency", currency }), [locale, currency] ); if (!info) return <p>Loading...</p>; const rate = info.data.zakat_rate / 100; const gold = info.data.nisab.find((n) => n.type === "gold"); const silver = info.data.nisab.find((n) => n.type === "silver"); const w = parseFloat(wealth) || 0; const n = parseFloat(nisabValue) || 0; const reachesNisab = n > 0 && w >= n; const due = reachesNisab ? w * rate : 0; return ( <section dir="auto"> <p>Gold nisab: {gold.value} g. Silver nisab: {silver.value} g. (source: {info.source})</p> <label>Zakatable wealth <input type="number" min="0" value={wealth} onChange={(e) => setWealth(e.target.value)} /> </label> <label>Nisab value in {currency} <input type="number" min="0" value={nisabValue} onChange={(e) => setNisabValue(e.target.value)} /> </label> <p>{n === 0 ? "Enter a nisab value." : reachesNisab ? "Zakat due: " + fmt.format(due) : "Below the nisab you entered."}</p> <small>Confirm rulings with a scholar.</small> </section> ); } Money math in floating point is fine for a display estimate, but for anything transactional use integer minor units.
Formatting and RTL tips
- Intl.NumberFormat handles currency symbols and digits per locale. Try "ar-SA" or "ur-PK" with a matching currency such as SAR or PKR.
- Set dir="auto" on text blocks so mixed Urdu/English content lays out correctly, or set dir="rtl" on the root when the whole UI is RTL.
- Use CSS logical properties (margin-inline-start instead of margin-left) so one stylesheet works in both directions.
- The API returns translations per language, so pass the lang parameter that matches your UI locale and read the matching key from the translations object.
Going further
Zakat is tied to a lunar year, so pairing the calculator with dates is natural. The Hijri Calendar API can help you build a reminder widget; check its page for the response shape. You can browse everything on the QuraniAPI home page, and the open repository is at sunnahsource-islamic-api on GitHub.
Wrap-up
We built a small component with a live, cached and bundled-sample data path, a simple 2.5% calculation using the API's rate, and locale-aware formatting. Next ideas: store the user's inputs locally, add a language switcher backed by the lang parameter, and show the guideline items text from the API under the result. Again, this is software only; please consult a scholar for your own zakat.

