new-personal-site/components/lib/editors/TinyMCE/useTinyMCE.tsx
Benjamin Toby 5587024789 Updates
2025-01-05 07:25:38 +01:00

35 lines
864 B
TypeScript

import React from "react";
import { TinyMCE } from "./tinymce";
let interval: any;
export default function useTinyMCE() {
const [tinyMCE, setTinyMCE] = React.useState<TinyMCE | null>(null);
React.useEffect(() => {
// @ts-ignore
if (window.tinymce) {
console.log("Tinymce already exists");
// @ts-ignore
setTinyMCE(window.tinymce);
return;
}
const script = document.createElement("script");
script.src = "https://datasquirel.com/tinymce-public/tinymce.min.js";
script.async = true;
document.head.appendChild(script);
script.onload = () => {
// @ts-ignore
if (window.tinymce) {
// @ts-ignore
setTinyMCE(window.tinymce);
}
};
}, []);
return { tinyMCE };
}