简体   繁体   English

流星/反应问题,getElementById

[英]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. 刚开始Web开发时,我将尝试给出所有相关信息,以开始使用Web Storm(IDE)和流星反应。 Now I was follow along a tutorial and can't figure out why the below code isn't working. 现在,我按照教程进行操作,无法弄清楚下面的代码为什么不起作用。 Specifically the reactDOM.render portion. 特别是reactDOM.render部分。

HTML 的HTML

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


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

JS 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. 请记住,Webstorm,Meteor和React对我来说都是新手。

You have a typo in method name: 您在方法名称中有错字:

document.getElementsById('root')

It should be: 它应该是:

document.getElementById('root')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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