首页 > 解决方案 > ReactJs 函数调用,而是看到一个表达式 no-unused-expressions

问题描述

我正在尝试在 reactjs 准备一个 restfulpi。但是因为我是reactjs新手,英文也不是很流利,所以遇到了一个问题。我的应用程序的目的是列出出版商的书籍。您可以从下面访问我的代码和错误。如果你帮助我,我可以做到。谢谢你。

错误:

第 21 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions

我的代码:

`` ` 
class App extends Component {
  state = {
    books:[]
  }
  componentWillMount(){
    axios.get('http://localhost:3000/books').then(( response)=>{
    this.setState({
      books: response.data
    })
    });
  }``

`` ` 
render() {
    let books = this.state.books.map((book) =>
    {
      return
      (
        <tr key={book.id}>
          <td>{book.id}</td>
          <td>{book.title}</td>
          <td>{book.rating}</td>
          <td>
            <Button color="success" size="sm" className="mr-2">Edit </Button>&nbsp;
            <Button color="danger" size="sm">Sil</Button>
          </td>
      </tr>
      )
    });``

`` ` 
 return (
  <div className="App container">
  <h1>Book List</h1><br></br>
  <Table> 
    <thead>
      <tr>
        <th>#</th>
        <th>Title</th>
        <th>Rating</th>
        <th>Actions</th>

      </tr>
    </thead>
    <tbody>
      {books}
    </tbody>
  </Table>

  </div>
);``

标签: javascriptreactjsfrontend

解决方案


您的方法中缺少该return语句render

render() {
     ....
     ...

   return (
      <tbody>
        {books}
      </tbody>
   )
}

推荐阅读