D
D
desuvin2015-04-25 22:30:53
React
desuvin, 2015-04-25 22:30:53

How to make react + require.js together?

If you google this question, then there is an option where jsx is compiled directly into the browser. However, I want to compile to js via babel and include it using require.js
The following is written in the require.js config:
require.config({
baseUrl: '/js/',
paths: {
react: "libs/react",
ui: " react"
}
});
requirejs(["ui/main"]);
In the jsx file

define(["react"], function(React) {
  class Test extends React.Component {
    render() {   
      return (

        <div>12312312123123</div>

      );
    }
  };

  React.render(
    <Test />,
    document.getElementById('test')
  );

});

babel works without problems, jsx also turns into js. require.js preloads React, and then this particular component fires.
It seems everything should be fine, but it displays some sort of terrible error
Uncaught TypeError: Super expression must either be null or a function, not undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Kostyurin, 2015-09-29
@JiLiZART

Judging by the text of the error, somehow the super() method, which is usually called in the constructor

constructor(props) {
   super(props); // вот тут получили undefined
}

And most likely they got it, because it didn’t work out from inheriting from React.Component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question