L
L
LB7772015-02-27 19:37:11
React
LB777, 2015-02-27 19:37:11

How to make proper interaction between jsx and React.js?

I started to study React, where javascript is actively used in the jsx format. For its transformation, Galpov's gulp-jsx package began to be used, which converts the jsx format into understandable js.
As a result, the line

<h1 onClick={this.goodbye}>{this.state.message}</h1>

converted to
React.DOM('h1', {onClick: this.goodbye}, [this.state.message])

which react.js does not want to understand
From this question, what am I doing wrong and how to make react.js and jsx files be friends?
PS: format string
React.DOM.h1({onClick:this.goodbye}, this.state.message));
works fine.
This code was taken from an example article

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LB777, 2015-03-02
@LB777

gulp-react should have been used instead of gulp-jsx

R
Ruslan Abdullaev, 2015-02-28
@rajdee

And how and where do you then connect the template compiled from jsx?
In theory, if you do not use the real-time JSX Transformer, but use precompilation on the server using react-tools, then you just need to include the compiled file at the end of body

....
      <script src="build/from_jsx.js"></script>
  </body>
</html>

That is, if you are not using jsx in its purest form, in combination with JSXTransformer
<script type="text/jsx">
      ...
      render: function() {
        return (
          <h1 onClick={this.goodbye}>{this.state.message}</h1>
        );
      }
      ...
    </script>

then you need to include the already compiled js.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question