{"id":14384448,"url":"https://github.com/Jeday/react-docx","last_synced_at":"2025-08-23T17:32:14.524Z","repository":{"id":54543814,"uuid":"270745424","full_name":"Jeday/react-docx","owner":"Jeday","description":"React reconciler for DOCX.js.","archived":false,"fork":false,"pushed_at":"2021-02-11T17:00:10.000Z","size":797,"stargazers_count":36,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-05-02T06:15:15.701Z","etag":null,"topics":["docx","node","react","web"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jeday.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-08T16:40:59.000Z","updated_at":"2024-03-18T11:18:18.000Z","dependencies_parsed_at":"2022-08-13T19:10:48.848Z","dependency_job_id":null,"html_url":"https://github.com/Jeday/react-docx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeday%2Freact-docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeday%2Freact-docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeday%2Freact-docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeday%2Freact-docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jeday","download_url":"https://codeload.github.com/Jeday/react-docx/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230716523,"owners_count":18269781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docx","node","react","web"],"created_at":"2024-08-28T18:01:23.772Z","updated_at":"2024-12-21T12:30:36.361Z","avatar_url":"https://github.com/Jeday.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# react-docx [![https://www.npmjs.com/package/react-docx](https://img.shields.io/npm/v/react-docx)](https://www.npmjs.com/package/react-docx)\n\nreact-docx is a React [reconciler](https://github.com/facebook/react/tree/master/packages/react-reconciler) for [DOCX.js](https://github.com/dolanmiu/docx).\n\n### Why\n\nLargely inspired by [R3F](https://github.com/react-spring/react-three-fiber) this library allows you write your DOCX documents in declarative style with reusable components. This is not a wrapper library and so DOCX classes are trasformed dynamicly into React components.\n\n### Limitations\n\nIn current early stage of library and because of inconsistent style of some methods in DOCX.js not all advanced DOCX features may work declaratively. Currently only single render run is supported, that means that using useState or passing another set of values to Context providers will have no effect. Alternatively you can call renderAsyncDocument again to rerender the document entirely.\n\n### Usage\n\nInstall peer dependencies React and Docx! They are needed for JSX and DOCX elements.\n\n```jsx\nimport React from \"react\"; // that is needed for jsx to work\nimport { renderAsyncDocument } from \"react-docx\";\nimport * as Docx from \"docx\"; // that is a peer dependency\n\nrenderAsyncDocument(\n  \u003csection\u003e\n    \u003cparagraph heading={Docx.HeadingLevel.HEADING_1}\u003e\n      You can pass props as if you are passing them to constructor\n    \u003c/paragraph\u003e\n    \u003cp\u003eThere are some helpful shortcuts for often used tags, like this\u003c/p\u003e\n    \u003cp\u003e\n      \u003ct\u003ethis one is for TextRun\u003c/t\u003e\n    \u003c/p\u003e\n    \u003cp\u003e\n      For text inside anything else than t or textrun tags, TextRun is created\n      under the hood\n      \u003ct break\u003e\n        For when docx objects have functional methods, you can pass function\n        name as a prop. Prop value will be passed as an argument, if you need to\n        pass many arguments use array instead.\n      \u003c/t\u003e\n    \u003c/p\u003e\n    \u003cp\u003e\n      Docx object is considered a tag if it has a constructor signature and is\n      exported out of DOCX.js. Object key is then converted to lowercase.\n      Everything you can make with raw DOCX.js(including mistakes), you can make\n      here.\n    \u003c/p\u003e\n    \u003cp\u003e\n      \u003cimg\n        src=\"base64 string or buffer object works\"\n        width={200}\n        height={200}\n      /\u003e\n      \u003chref\n        src=\"http://localhost:8080\"\n        label={\"For images and links shortcuts object are provided\"}\n      /\u003e\n      This allows for removal of boilerplate for often used objects. In future\n      more such object will be implemented.\n    \u003c/p\u003e\n    \u003cp\u003e\n      Sections are root tags for valid DOCX. If you want to have multiple\n      sections, pass React Fragment with them to renderAsyncDocument.\n    \u003c/p\u003e\n    \u003cComponent text=\"You can use components of course, just like in react!\"\u003e\n      \u003ct\u003eA child\u003c/t\u003e\n    \u003c/Component\u003e\n  \u003c/section\u003e\n).then((document) =\u003e console.log(\"This is rendered docx document\", document));\n\nconst Component = ({ children, text }) =\u003e {\n  const ref = React.useRef(null); // use can use refs to access docx objects\n  React.useLayoutEffect(() =\u003e {\n    // you can use LayoutEffect hook in combination with refs to write imperative code( hacks for example)\n    console.log(ref.current);\n    // because of useLayoutEffect nature it will work in single render as opposed to regular useEffect\n  }, []);\n  return (\n    \u003cp ref={ref}\u003e\n      \u003ct\u003e{text}\u003c/t\u003e\n      {children}\n    \u003c/p\u003e\n  );\n};\n```\n\n### API\n\nFor details on Docx refer to [it's docs](https://docx.js.org).\n\nCore render function, returns promise that is resolved with rendered document object. You can use Docx tools to convert it to blob, as according to Docx examples.\n\n```jsx\nrenderAsyncDocument(ReactElements, DocumentProperites, FileProperties);\n```\n\n### Future Plans\n\n- More shortcuts\n- More fictive objects to remove boilerplate\n- Add mutations to Document tree\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeday%2Freact-docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJeday%2Freact-docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJeday%2Freact-docx/lists"}