35 lines
864 B
TypeScript
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 };
|
|
}
|