Try the fastest and simplest way to install ONLYOFFICE

Integration with ReactJS

Integration questions/issues

Integration with ReactJS

Postby Abhishek_Nalin » Mon Mar 26, 2018 2:21 pm

Hi,
I went through the integration example of NodeJS which was done using EJS. I was looking for a ReactJS example.

I have installed document server on IP - AA.BB.YY.XX and it is working fine.
We have a ReactJS frontend. I added the script tag in our index.html
<script type="text/javascript" src="http://AA.BB.YY.XX/web-apps/apps/api/documents/api.js"></script>

When the user clicks on the word document in my app I call a function named openEditor and pass the url

openEditor = (url) => {
new DocsAPI.DocEditor("placeholder", {
"document": {
"fileType": "docx",
"key": "Khirz6zTPdfd7",
"title": "Example Document Title.docx",
"url": url
},
"documentType": "text"
});
}

However this doesn't work because I get the compilation error 'DocsAPI' is not defined'
Is there a way to make this work? How do I define DocsAPI in my ReactComponent?
Is this the right way to integrate with React?

Regards
Abhishek
Abhishek_Nalin
 
Posts: 1
Joined: Mon Mar 26, 2018 1:32 pm

Re: Integration with ReactJS

Postby Maxim » Tue Apr 03, 2018 10:25 am

Hello!
'DocsAPI' is not defined means that there is no access to API
what do you get if you go to http://AA.BB.YY.XX/web-apps/apps/api/documents/api.js?
Maxim
 
Posts: 1747
Joined: Tue Oct 11, 2016 2:34 pm

Re: Integration with ReactJS

Postby BorisZR » Thu Jun 28, 2018 12:29 pm

Hello,

You have to use window explicity to access the DocsAPI object.
Code snippet:
Code: Select all
import React, { Component } from 'react';
import './App.css';

class App extends Component {
  render() {
    return (
        <div id="placeholder"></div>
    );
  }

  componentDidMount() {
    let config = {
      "document": {
        "fileType": "docx",
        "key": "...",
        "title": "...",
        "url": "..."
      },
      "documentType": "text",
      "editorConfig": {
        "callbackUrl": "..."
      }
    };
    new window.DocsAPI.DocEditor("placeholder", config);
  }
}

export default App;


Best regards,
Boris
BorisZR
 
Posts: 1
Joined: Thu Jun 28, 2018 12:25 pm


Return to API

Who is online

Users browsing this forum: No registered users and 2 guests