Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of docx4js in ReactJS #27

Closed
AkshayCloudAnalogy opened this issue Apr 13, 2019 · 1 comment
Closed

Use of docx4js in ReactJS #27

AkshayCloudAnalogy opened this issue Apr 13, 2019 · 1 comment

Comments

@AkshayCloudAnalogy
Copy link

AkshayCloudAnalogy commented Apr 13, 2019

I am a newbie in React and i am not able to get this working in React.
I have use axios to get the response of the file as "arraybuffer" and successfully able to get the data from docx4js.load but i am not able to understand how to render that on the screen.

Here is the code if that might help:

import React, { useEffect } from "react";
import axios from "axios";
import docx4js from "docx4js";

const Docx = ({ previewedRecord, token }) => {
  useEffect(() => {
    axios
      .get(previewedRecord.url, {
        responseType: "arraybuffer",
        headers: {
          Authorization: "Bearer " + token
        }
      })
      .then(res => {
        docx4js.load(res.data).then(docx => {
          console.log("[Docx.jsx] docx:", docx); // I am able to get the data here.
        })
          .catch(err => {
            console.error("[Docx.jsx] err:", err);
          });
      })
      .catch(err => {
        console.error("[Docx.jsx] err:", err);
      });
  }, []);

  return <div id="docx" />; // I want the Docx to be rendered here.
};

export default Docx;

Here is the screenshot of the docx returned:

image

@lalalic
Copy link
Owner

lalalic commented Oct 18, 2021

you can use docx.render((type,props,children)=><YourComponentForType {...props}/>)

@lalalic lalalic closed this as completed Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants