1

I am creating hierarchical React Component using JSX. The code does not show any errors but nothing shows up on my page. Here is my code below.

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>React Test</title>
</head>
<body>
    <div id="app">

    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
    <script type="text/babel">
        var Converter = React.createClass({
            render: function() {
                return <inputBox />;
            }
        });

        var inputBox = React.createClass({
            render: function() {
                return <h1>Hello World!</h1>;
            }
        });

        ReactDOM.render(
            React.createElement(Converter, null),
            document.getElementById('app'),
        );
    </script>
</body>
</html>

when i use

ReactDOM.render(
    React.createElement(inputBox, null),
    document.getElementById('app')
);

Hello World! Shows up. What am I doing wrong? I have tried debugging a lot but could not figure out anything.

0

2 Answers 2

4
            return <InputBox />;

and NOT

            return <inputBox />;

Do not use lowercase when you are initiating react component. Otherwise, it will be considered as simple HTML tag.

Sign up to request clarification or add additional context in comments.

2 Comments

You are awesome. I have spend last 5 hours debugging that and could not figure out this thing. The components should always have camel case starting with a capital. You rock man!
Your are Welcome 👋 .
1

instead of

var inputBox = React.createClass({

Use this:

var InputBox = React.createClass({

Because react component must start with uppercase otherwise it will be treated as html elements.

Check the working snippet:

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>React Test</title>
</head>
<body>
    <div id="app">

    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
    <script type="text/babel">
        var Converter = React.createClass({
            render: function() {
                return <InputBox />;
            }
        });

        var InputBox = React.createClass({
            render: function() {
                return <h1>Hello World!</h1>;
            }
        });

        ReactDOM.render(
            <Converter/>,
            document.getElementById('app'),
        );
    </script>
</body>
</html>

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.