1

Hi guys i am new to Reactjs and i can not get it to work.

First i got the unexpected token error that most reactjs starters have encountered, after reading the suggested solutions

  • i took all react js code and put it in a separate .js file like below

    <script src="include_js/react.js" type="text/jsx"></script>
    
  • than i added the suggested comments on top of the file

    /** @jsx React.DOM */
    
    ReactDOM.render(
      <h1>Hello</h1>,
      document.getElementById('indicators')
    );
    

The error is gone but i think react.js is'nt executed at all <h1>Hello</h1> is not added to "indicators" div. I see it is downloaded in network tab but not listed in source tab(Chrome Dev Tools)

NOTE: I have added both required plugins beforehand

    <script src="react-0.14.8.min.js"></script>
    <script src="react-dom-0.14.8.min.js"></script>

SOLVED I changed type="text/jsx" to type="text/babel" also included <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script> as @kujira mentioned. I also removed /** @jsx React.DOM */ as it is not needed anymore

Community
  • 1
  • 1
Herbi Shtini
  • 2,002
  • 29
  • 34
  • 1
    Did you try the solutions suggested in the question you linked? Looks like your scripts are not using type="text/babel". The pragma you added to the top of your file is outdated; see his edit http://stackoverflow.com/a/20913732/4206756 which says it's no longer needed in react 0.12+ (you seem to be using 0.14.8). – Hypaethral Apr 07 '16 at 13:20
  • I think have also tried type="text/babel" but i am not totally sure, i will give it a try. thnx – Herbi Shtini Apr 07 '16 at 13:30
  • 1
    Make sure to add babel plugin: `` if using `type="text/babel"` – Yuya Apr 07 '16 at 14:38
  • I see, is there any alternative way if you don't want to add an extra plugin(babel), i think i read somewhere that it was not required – Herbi Shtini Apr 07 '16 at 14:43
  • 1
    It is not required if you transform the JSX into JS beforehand. This plugin does it on the fly. – yachaka Apr 07 '16 at 15:35

0 Answers0