// src/react/index.ts
import { useCallback, useEffect, useState } from "react";
function LatexRuntime(props) {
  const renderLatex = useLatex();
  useEffect(() => {
    renderLatex(props).catch(props.onError || (() => {
    }));
  });
  return null;
}
function useLatex() {
  const [latex, setLatex] = useState(null);
  const render = useCallback(
    async (options) => {
      if (latex) {
        return latex.run(options);
      }
    },
    [latex]
  );
  useEffect(() => {
    (window.latexJsonp = window.latexJsonp || []).push(setLatex);
    return () => {
      const index = window.latexJsonp.indexOf(setLatex);
      if (index > -1) {
        window.latexJsonp.splice(index, 1);
      }
    };
  }, []);
  return render;
}
export {
  LatexRuntime,
  useLatex
};
//# sourceMappingURL=index.js.map
