我是ReactJS的新手,我想从Traversy Media的视频教程中学习基础知识,并且我完全按照他的操作来应用代码。但是我陷入了in this part的困境,因为遇到这样的错误,无法编译:
这是我编写的代码:
import React, { Component } from 'react';
import Todos from './components/Todos';
import './App.css';
class App extends Component {
state = {
todos: [
{
id: 1,
title: 'Take out he trash',
completed: false
},
{
id: 2,
title: 'Have a Dinner',
completed: false
},
{
id: 3,
title: 'Meeting with Boss',
completed: false
},
]
};
render() {
return (
<div className="App">
<Todos todos={this.state.todos} />
</div>
);
}
}
export default App;
import React, {Component} from 'react';
import TodoItem from './TodoItem';
class Todos extends Component {
render() {
return this.props.todos.map((todo) => (
<TodoItem/>
));
}
}
export default Todos;
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return{
<div>
<p>Hello</p>
</div>
}
}
}
export default TodoItem;
答案 0 :(得分:2)
应该是
return(
<div>
<p>Hello</p>
</div>
)
使用大括号表示方法或变量
答案 1 :(得分:2)
它应该看起来像这样-
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;
答案 2 :(得分:1)
TodoItem.js返回语句中存在语法错误。只需替换此代码
import React, { Component } from 'react';
export class TodoItem extends Component{
render(){
return(
<div>
<p>Hello</p>
</div>
)
}
}
export default TodoItem;