UNPKG

react-font-tools

Version:

Tools to help you with font of your app.

28 lines (25 loc) 873 B
import { useState, useEffect } from 'react'; var useFontSize = function () { var _a = useState("1rem"), finalFontSize = _a[0], setFinalFontSize = _a[1]; useEffect(function () { setFontSize(getFontSize() || "1rem"); }, []); useEffect(function () { if (document) document.body.style.fontSize = finalFontSize; }, [finalFontSize]); var getFontSize = function () { if (typeof window === 'undefined') return null; return window.localStorage.getItem("font-size"); }; var setFontSize = function (value) { if (typeof window === 'undefined') return; window.localStorage.setItem("font-size", value); setFinalFontSize(value); }; return [finalFontSize, setFontSize]; }; export { useFontSize }; //# sourceMappingURL=index.es.js.map