Giter Club home page Giter Club logo

making-a-custom-react-renderer's Introduction

Building a custom React renderer

Build Status

Let's make a custom React renderer ๐Ÿ˜Ž

Introduction

This 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 -

  • Part 1 - Creating a React reconciler (using react-reconciler package).

  • Part 2 - Creating a public interface to the reconciler i.e "Renderer".

  • Part 3 - Creating a render method to flush everything to the host environment we need.

Brief

Part-I

In part one, we will create a React reconciler using the react-reconciler package. We will implement the renderer using Fiber as it has a first-class renderer API for creating custom renderer.

Part-II

In 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.

Part-III

In part three, we will create a render method which will render our input component.

What we will build?

We 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.

We will use officegen for this. I'll explain some of it's basic concepts here.

Officegen can generate Open Office XML files for Microsoft Office 2007 and later. It generates a output stream and not a file. It is independent of any output tool.

Creating a document object

let doc = officegen('docx', { __someOptions__ });

Generating output stream

let output = fs.createWriteStream (__filePath__);

doc.generate(output);

Events

finalize - It is fired after a stream has been generated successfully.

error - Fired when there are any errors

Running the project

git clone https://github.com/nitin42/Making-a-custom-React-renderer
cd Making-a-custom-React-renderer
yarn install
yarn example

After you run yarn example, a docx file will be generated in the demo folder.

Contributing

Suggestions to improve the tutorial are welcome ๐Ÿ˜ƒ.

If you've completed the tutorial successfully, you can either watch/star this repo or follow me on twitter for more updates.

Sponsor

making-a-custom-react-renderer's People

Contributors

bogas04 avatar chentsulin avatar ergenekonyigit avatar johnrees avatar jrop avatar monkindey avatar nitin42 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.