在我的主要文件,我有這樣的代碼ReactDOM.render不能造成什麼
import phoneReactElement from "../components/phone.js";
ReactDOM.render(<phoneReactElement />, document.getElementById('phoneComponentTester'));
「../components/phone.js」 看起來是這樣的:
import React, { Component } from 'react';
class TestComponent extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>IT WORKED</div>
);
}
}
export default TestComponent;
好像它的工作正確,因爲控制檯中沒有錯誤,並且我可以在Google Chrome工具中看到該元素,但它似乎是空的。它不顯示「IT WORKED」,我在這裏做錯了什麼?
這適用於我:http://plnkr.co/edit/xfThQCIsF3PAc0OA2GTo?p=preview你可以仔細檢查你正在導入正確的'phone.js'嗎? –
感謝您將它們放在一起,似乎有一個區別可能是我導出組件(我認爲我正確地做了這件事)。我確認phone.js是正確的。 –
我在下面回答了這個問題,但只是注意到這是一個可能的重複https://stackoverflow.com/questions/30373343/reactjs-component-names-must-begin-with-capital-letters – djfdev