ONLYOFFICE / document-editor-react

React component for ONLYOFFICE Document Server
Apache License 2.0
34 stars 7 forks source link

Unable to refresh history data using refreshHistory method in React component #42

Open samsam002 opened 3 months ago

samsam002 commented 3 months ago

I am using the OnlyOffice component in a React project and encountering an issue when trying to refresh the history data using the refreshHistory method. The method is being called within the onRequestHistory callback, but it throws a TypeError indicating that refreshHistory is not a function. Here's the relevant code snippet:

onRequestHistory: async (event) => {
  console.log('Requesting history data...', event);
  const data = await get(`/contracts/${itemId}/history`);
  event?.target?.docEditor.refreshHistory({
    currentVersion: data.currentVersion,
    history: data.history,
  });
},

The error message received is:

TypeError: editor.refreshHistory is not a function

I have tried accessing the refreshHistory method through event.target.docEditor, but it doesn't seem to be available.

Additional context:

I am using the OnlyOffice component in a React project. The OnlyOffice component is initialized with the necessary props and configurations. The onRequestHistory callback is triggered when the history data needs to be refreshed. I have followed the documentation and examples provided for integrating OnlyOffice in a React project. I would appreciate any guidance or suggestions on how to properly refresh the history data using the OnlyOffice component in a React environment. If there are any changes in the API or recommended approaches, please let me know.

in other words : From where i can get the docEditor instance in the document-editor-react implementation.

aleksandrfedorov97 commented 3 months ago

Hi samsam002, you can get the docEditor instance like this: var docEditor = window.DocEditor.instances[id] where id is the сomponent unique identifier.