A
A
Alexander Wolf2015-12-21 10:51:19
JavaScript
Alexander Wolf, 2015-12-21 10:51:19

How to switch from blaze to react?

Good afternoon! Our entire application is written in Iron:Router + Blaze Templates. After the release of Flow Router, we want to switch to it. However, it works great with React, which we would also be interested in implementing.
So, subject: how to transfer the project from blaze to react "in parts"? Interested in intelligent approaches. It's so clear that you can freeze the project and rewrite it using React.
UPDATE:
At the moment I wrote the following wrapper:

ReactToBlaze = function(templateName, component) {
  if(Meteor.isServer) return; // Blaze не пашет на сервере

  var templateClass = new Template(templateName, () => new HTML.DIV);
  Template[templateName] = templateClass;

  templateClass.onRendered(function() {
    this.autorun(() => {
      var data = Template.currentData() || {};
      var c = React.createElement(component, data);
      c._meteorTemplate = this;
      this._reactComponent = ReactDOM.render(c, this.firstNode);
    });
  });

  templateClass.onDestroyed(function() {
    var template = this;
    var res = ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(template._reactComponent).parentElement);
    if(!res) {
      console.error('Не удалось размонтировать элемент');
    }
  });

  return templateClass;
};

I pass the name of the template for Blaze and the component itself there. I have a ready template.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vsuhachev, 2015-12-22
@mannaro

I can express general considerations - include react in the project and, in the presence of the old technology, gradually rewrite the application in parts to the new one, and immediately use react so that there is no need to redo something later. For some time, react and blaze will work in parallel, then there will be only one react.

S
Shane Matte, 2017-02-07
@mattedev

No need to freeze. Alternatively, rewrite the project, then install the update.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question