Meteor-React Error: Target Container is not a DOM element

元气小坏坏 提交于 2019-12-24 06:23:19

问题


I'm doing this tutorial on Meteor1.4 with React and i'm getting this error:

Uncaught Error: _registerComponent(...): Target container is not a DOM element.(…)

I have looked at this similar answer, but this being Meteor i can't tell why it's happening.

main.html

<head>
  <title>React Meteor Voting</title>
</head>
<body>
  <div class="render-target"></div>
</body>

main.js

import React, { Component } from 'react';
import {Meteor} from 'meteor/meteor';
import { render } from 'react-dom';

Meteor.startup(() => {
  render(<App />, document.getElementById('render-target'));
});

class App extends Component {
  render(){
    return (
      <h1>Hello!</h1>
    );
  }
}

package.json

{
  "name": "MeteorReact1.4",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "babel-runtime": "6.18.0",
    "meteor-node-stubs": "~0.2.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  }
}

回答1:


In your Meteor startup's render method you are getting the element by id wherein in your html file, no such element exists. Replace class with id in the div in your html file's body



来源:https://stackoverflow.com/questions/41514549/meteor-react-error-target-container-is-not-a-dom-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!