问题
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