简体   繁体   中英

Adding React Template to React

I'm trying using react-template. I'm using grunt, browserify and react-templatify. The code is compliled without errors but nothing is displayed. The code is simple.

hello.rt.js code compiled with react-template

import React from 'react';
var helloRT = function () {
    return React.createElement('div', {}, 'Hola Rt');
};

export default helloRT;

Rtexample.js

import React, { Component }  from 'react';
import helloRT from './hello.rt.js';



class Rtexample extends Component {
  
    render(){
      return helloRT;
   }
}



export default Rtexample;

The solution:

Replace var helloRT = function () for function helloRT() in hello.rt.js

Thanks community for nothing.

You can configure Gruntfile.js like this:

reactTemplates: {
        dist: {
          src: ['./src/components/**/*.rt'], //glob patterns of files to be processed
          options: {
            modules: 'es6',  //possible values: (amd|commonjs|es6|typescript|none)
            format: 'stylish' //possible values: (stylish|json)
          }
        }
      },

es6 is important. This solved the problem. Compile rt file like this:

import * as React from 'react';
import * as _ from 'lodash';
export default function () {
    return React.createElement('div', {}, 'Hola Rt cambiada');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM