简体   繁体   中英

Problems with meteor/react, getElementById

Just starting web development I'll try and give all relevant information, to start I'm using web storm(IDE) and meteor react. Now I was follow along a tutorial and can't figure out why the below code isn't working. Specifically the reactDOM.render portion.

HTML

<head>
    <title>Personal Project</title>
</head>


<body>
    <div id = "root"></div>
</body>

JS

import React from 'react';
import ReactDOM from 'react-dom';

function formatName(user) {
    return user.firstName + ' ' + user.lastName;
}

const user = {
    firstName: 'Justin',
    lastName: 'Schneider'
};

const element = (
    <h1> Hello, {formatName(user)}!</h1>
);

ReactDOM.render(
    element,
    document.getElementsById('root')
);

When I try locally hosting the above, nothing happens besides the title being set to "Personal Project". Any help would be appreciated and as well as debugging tips. Please keep in mind Web storm, Meteor, and React are all new to me.

You have a typo in method name:

document.getElementsById('root')

It should be:

document.getElementById('root')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM