From 87a7ca9701832d1d4dab92c9e4b365b22f201fed Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Thu, 20 Jun 2024 22:32:02 +0300
Subject: [PATCH] load only once

---
 wax-prosemirror-core/src/WaxView.js | 40 +++++++++++++++++------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js
index b166fe6f5..35db8f6bb 100644
--- a/wax-prosemirror-core/src/WaxView.js
+++ b/wax-prosemirror-core/src/WaxView.js
@@ -1,6 +1,6 @@
 /* eslint-disable consistent-return */
 /* eslint-disable react/prop-types */
-import React, { useContext, useCallback, useEffect } from 'react';
+import React, { useContext, useCallback, useEffect, useRef } from 'react';
 import styled from 'styled-components';
 import { WaxContext } from './WaxContext';
 import ComponentPlugin from './ComponentPlugin';
@@ -20,35 +20,41 @@ const WaxPortals = ComponentPlugin('waxPortals');
 const WaxOverlays = ComponentPlugin('waxOverlays');
 
 const WaxView = props => {
-  const { autoFocus, configHash } = props;
-  console.log(configHash);
+  const { autoFocus } = props;
+
   const main = useWaxView(props);
-  console.log(main);
+
   // const {
   //   pmViews: { main },
   // } = useContext(WaxContext);
 
-  const editorRef = useCallback(
-    element => {
-      console.log('WAXXXX');
-      if (element && main) {
-        element.replaceChildren(main?.dom);
-      }
-
-      // return () => element.remove();
-    },
-    [main],
-  );
-
   useEffect(() => {
     if (autoFocus && main) {
       main.focus();
     }
   }, [autoFocus]);
 
+  const divRef = useRef(null);
+
+  const initialize = useCallback(() => {
+    console.log('Initializing only once');
+
+    // You can perform any initialization logic here
+    // This code will only run once when the component mounts
+    if (divRef.current) {
+      console.log('dkddkkdk', main?.dom);
+      divRef.current.replaceChildren(main?.dom);
+      // Perform some operation with divRef.current
+    }
+  }, [main]);
+
+  useEffect(() => {
+    initialize();
+  }, [initialize]);
+
   return (
     <EditorContainer>
-      <div ref={editorRef} />
+      <div ref={divRef} />
       <WaxOverlays activeViewId="main" group="main" />
       <WaxPortals />
     </EditorContainer>
-- 
GitLab