0

I'm following a simple ReactJS tutorial on udemy and for some reason my code which seems to be the same line for line is not working, nor am I getting any errors in the dev tools in chrome.

Here is my code, but I can't seem to figure out why it's not working. I'm using Brackets as my IDE and am also using chrome.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <script src="https://unpkg.com/[email protected]/dist/react.js"></script>
        <script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.20/browser.js"></script>
    </head>
    <body>
        <div id="app">
        </div>
        <script type="text/babel">

        var secondComp2 = React.createClass({

            render: function () {

                return (

                    <div>
                        <h1>{this.props.name}</h1>
                    </div>

                )

            }

        });

        ReactDOM.render(

            <secondComp2 name="hello world" />,
            document.getElementById('app')

        );

        </script>
    </body>
</html>

2 Answers 2

2

React components are always defined in PascalCase. This will solve your problem.

<script type="text/babel">    
        var SecondComp2 = React.createClass({    
            render: function () {    
                return (    
                    <div>
                        <h1>{this.props.name}</h1>
                    </div>    
                );    
            }    
        });    
        ReactDOM.render(    
            <SecondComp2 name="hello world" />,
            document.getElementById('app')    
        );    
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

this is correct too but the guy above you was first :-)
Happy Coding :)
1

Its a rule that all React components must starts with a upper case letter, because small letters are treated as HTML elements,

So use this: SecondComp2 instead of secondComp2.

Check the working fiddle: https://jsfiddle.net/5nvd3o6t/

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.