0

I'm having a very simple issue with using React.js on CodePen! I'm new to React, and I'm trying to use the React library on CodePen. It just doesn't appear to be working for some reason, even though I'm also using Babel as the pre-processor.

I feel like this may have something to do with the version I'm using? - 15.3.1

http://codepen.io/anfperez/pen/aBomwp

My code:

var React = require('react');
var ReactDOM = require('react-dom');

var Test = React.CreateClass({
  render: function() {
    return (
    <h2> Yo </h2>
    );
  }
});

ReactDOM.render(<Test />, getElementById("test"));

Any tips are appreciated.

4 Answers 4

1

The problem is RequireJS is not needed for your example. Please try: http://codepen.io/anon/pen/JbPWeO

var Test = React.createClass({
    render: function() {
        return (
            <h2> Yo </h2>
        );
    }
});

ReactDOM.render(<Test />, document.getElementById("test"));
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I tried putting in different versions of Require.js, but none of them seem to work. I'm using the latest version of React on CodePen (15.3.1) so I'm not sure if that's actually the issue or not, unless there's a version of Require.js that works best with that version of React...
@Leia_Organa My apologies, I didn't read this completely. Removing the first two lines of your example will allow it to work. In this case, you do not need RequireJS for your example to function. Please see: codepen.io/anon/pen/JbPWeO
Thank you! That was a simple fix and totally worked!
1

You should add these external scripts in your javascript pen settings :

https://unpkg.com/react/umd/react.development.js

and

https://unpkg.com/react-dom/umd/react-dom.development.js

Comments

0

Here are some suggestions:

  • You should also need to include ReactDOM as you only included React in Codepen.
  • Line 4 should be React.createClass (createClass should be in Camel case).
  • Line 12 should be document.getElementById instead of getElementById

1 Comment

My pleasure. I just check the code and assume these might be causing you problem although I didn't try to run that code.
0

Add react-js first and then add react-dom js, the order matters in code pen or it will show error

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.