简体   繁体   English

ReactJs函数调用,而是看到一个表达式no-unused-expressions

[英]ReactJs function call and instead saw an expression no-unused-expressions

I'm trying to prepare a restfulpi at reactjs. 我正在尝试在reactjs上准备restfulpi。 But because I'm new to reactjs and I'm not very fluent in English, I have encountered a problem. 但是因为我是ReactJS的新手,而且我的英语不太流利,所以遇到了一个问题。 the purpose of my application is to list the books of a publisher. 我申请的目的是列出出版商的书籍。 you can access my code and error from below. 您可以从下面访问我的代码和错误。 I can do it if you help me. 如果您能帮助我,我可以做到。 Thank you. 谢谢。

Error: 错误:

Line 21: Expected an assignment or function call and instead saw an expression no-unused-expressions 第21行:预期分配或函数调用,而是看到一个表达式no-unused-expressions

My Codes: 我的代码:

`` ` 
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>
);``

You are missing the return statement in your render method. 您在render方法中缺少return语句。

render() {
     ....
     ...

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

Try this: 尝试这个:

render() {
  const 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 <tbody>{books}</tbody>;
}

According to this answer it is a common mistake in the render function. 根据此答案,这是渲染功能中的常见错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 得到预期赋值或函数调用的错误,而是看到一个表达式 no-unused-expressions? - Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions? 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React Object.keys-需要一个赋值或函数调用,而是看到一个表达式no-unused-expressions - Object.keys - Expected an assignment or function call and instead saw an expression no-unused-expressions 如何解决这个 期望赋值或函数调用,而是看到一个表达式 no-unused-expressions - how to solve this Expected an assignment or function call and instead saw an expression no-unused-expressions 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions “预期分配或 function 调用,而是在我的聊天应用程序中看到一个表达式 no-unused-expressions” - “Expected an assignment or function call and instead saw an expression no-unused-expressions” in my chat app 第 55:11 行:期望一个赋值或 function 调用,而是看到一个表达式 no-unused-expressions - Line 55:11: Expected an assignment or function call and instead saw an expression no-unused-expressions 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM