6

JSX Transformer Causes Errors

When I convert my react files using the converter from react-tools

      $ jsx public/dev/jsx public/prod/js --no-cache-dir

Or when I convert with grunt-react

      $ grunt react

My production file breaks because the conversion uses React.createElement and the error says that this function is undefined.

      <h1>{this.state.title}</h1>

converts to:

      React.createElement("div", null, 
      React.createElement("h1", null, this.state.title)

instead of:

      React.DOM.h1(null, this.state.title)

The live converter works fine because it uses React.DOM.h1(null, this.state.title). This line of code works well with react, but the React.createElement() function does not work and is not found.

How can I force my auto converter, either JSX or grunt, to convert to React.DOM.h1(null) instead of React.createElement(h1, null). Why does the converter use this function?

4

2 に答える 2

4

coffee-react-transform ライブラリでも同じエラーが発生しました。これらのライブラリは、React 0.12 用に更新されています。まだ React 0.11 を使用している場合は、おそらく grunt-react を少し古いバージョンにロールバックするか、React 0.12 にアップグレードする必要があります。

于 2014-11-03T17:41:09.477 に答える