D
D
Dmitry Potylitsyn2017-03-02 04:35:26
JavaScript
Dmitry Potylitsyn, 2017-03-02 04:35:26

Why React element creation doesn't work?

Hello! One strange feature is of interest. Here is a code example:
There is a React-Router object in which a dynamic route is formed:

{
      path: '<какой-то путь>',
      getComponent(location, cb) {
        require.ensure([], require => {
          cb(null, test());
        }, '<какой-то чанк-нейм>');
      }
    }

The task of the further code is to "throw" additional. properties to the root component, which we get from the dynamic route above. So far, I've tried to just render the component without passing additional properties.
function PropsPasser(element, props) {
  class WrapClass extends React.Component {
    constructor(props){
      super(props);
    }
    render(){
      //return <element />              <------- ТАК НЕ РАБОТАЕТ (пустая страница)! ПОЧЕМУ?
      return React.createElement(element)
    }
  }
  return WrapClass
}

function test(type) {
  let asyncObj = require('<какой-то путь>');
  let asyncRoute = asyncObj.default;
  let propsPasser = PropsPasser(asyncRoute, {type: "pew-pew"});
  return propsPasser;
}

As you know from the React documentation, the < element / > and React.createElement(element) constructs should be essentially identical. What did I miss?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question