react根元件引用子元件問題
阿新 • • 發佈:2018-12-14
<*** />is using incorrect casing. Use PascalCase for React components,
import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import toDoApp from './components/todoApp' class App extends Component { render() { return ( <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <toDoApp /> </header> </div> ); } } export default App;
上面是原始碼。沒看出有什麼問題。後來不斷測試。發現引入元件標籤第一位一定要大寫
import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import ToDoApp from './components/todoApp' class App extends Component { render() { return ( <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <ToDoApp/> </header> </div> ); } } export default App;