{"id":16513725,"url":"https://github.com/nitin42/making-a-custom-react-renderer","last_synced_at":"2025-04-08T16:09:45.872Z","repository":{"id":46053241,"uuid":"104637286","full_name":"nitin42/Making-a-custom-React-renderer","owner":"nitin42","description":"Tutorial on how to make a custom React renderer","archived":false,"fork":false,"pushed_at":"2022-12-06T19:46:34.000Z","size":276,"stargazers_count":1310,"open_issues_count":14,"forks_count":92,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-10-12T16:09:58.620Z","etag":null,"topics":["officegen","parsing","react","reconciler","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nitin42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-24T10:57:21.000Z","updated_at":"2024-10-12T15:53:34.000Z","dependencies_parsed_at":"2023-01-23T12:25:15.500Z","dependency_job_id":null,"html_url":"https://github.com/nitin42/Making-a-custom-React-renderer","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/nitin42%2FMaking-a-custom-React-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitin42%2FMaking-a-custom-React-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitin42%2FMaking-a-custom-React-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitin42%2FMaking-a-custom-React-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitin42","download_url":"https://codeload.github.com/nitin42/Making-a-custom-React-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247878022,"owners_count":21011158,"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":["officegen","parsing","react","reconciler","tutorial"],"created_at":"2024-10-11T16:10:03.008Z","updated_at":"2025-04-08T16:09:45.855Z","avatar_url":"https://github.com/nitin42.png","language":"JavaScript","readme":"# Building a custom React renderer\n\n[![Build Status](https://travis-ci.org/nitin42/Making-a-custom-React-renderer.svg?branch=master)](https://travis-ci.org/nitin42/Making-a-custom-React-renderer)\n\n\u003e Let's make a custom React renderer 😎\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn.filestackcontent.com/5KdzhvGRG61WMQhBa1Ql\" width=\"630\" height=\"350\"\u003e\n\u003c/p\u003e\n\n## Introduction\n\nThis is a small tutorial on how to build your custom React renderer and render the components to the host environment you need. The tutorial is divided into three parts -\n\n* **Part 1** - Creating a React reconciler (using [`react-reconciler`](https://github.com/facebook/react/tree/master/packages/react-reconciler) package).\n\n* **Part 2** - Creating a public interface to the reconciler i.e \"Renderer\".\n\n* **Part 3** - Creating a render method to flush everything to the host environment we need.\n\n## Brief\n\n### [Part-I](./part-one.md)\n\nIn part one, we will create a React reconciler using the [`react-reconciler`](https://github.com/facebook/react/tree/master/packages/react-reconciler) package. We will implement the renderer using Fiber as it has a first-class renderer API for creating custom renderer.\n\n### [Part-II](./part-two.md)\n\nIn part two, we will create a public interface to the reconciler i.e a renderer. We will create a custom method for `createElement` and will also architect the component API for our example.\n\n### [Part-III](./part-three.md)\n\nIn part three, we will create a render method which will render our input component.\n\n## What we will build?\n\nWe will create a custom renderer that will render a React component to a word document. I've already made one. Full source code and the documentation for that is available [here](https://github.com/nitin42/redocx).\n\nWe will use [officegen](https://github.com/Ziv-Barber/officegen) for this. I'll explain some of it's basic concepts here.\n\nOfficegen can generate Open Office XML files for Microsoft Office 2007 and later. It generates a output stream and not a file.\nIt is independent of any output tool.\n\n**Creating a document object**\n\n```js\nlet doc = officegen('docx', { __someOptions__ });\n```\n\n**Generating output stream**\n\n```js\nlet output = fs.createWriteStream (__filePath__);\n\ndoc.generate(output);\n```\n\n**Events**\n\n`finalize` - It is fired after a stream has been generated successfully.\n\n`error` - Fired when there are any errors\n\n## Running the project\n\n```\ngit clone https://github.com/nitin42/Making-a-custom-React-renderer\ncd Making-a-custom-React-renderer\nyarn install\nyarn example\n```\n\nAfter you run `yarn example`, a docx file will be generated in the [demo](./demo) folder.\n\n## Contributing\n\nSuggestions to improve the tutorial are welcome 😃.\n\n**If you've completed the tutorial successfully, you can either watch/star this repo or follow me on [twitter](https://twitter.com/NTulswani) for more updates.**\n\n\u003ca target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/FCRW65HPiwhNtebDx2tTc53E/nitin42/Making-a-custom-React-renderer'\u003e\n  \u003cimg alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/FCRW65HPiwhNtebDx2tTc53E/nitin42/Making-a-custom-React-renderer.svg' /\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitin42%2Fmaking-a-custom-react-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitin42%2Fmaking-a-custom-react-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitin42%2Fmaking-a-custom-react-renderer/lists"}