简体   繁体   English

如何解决解析错误:缺少分号?

[英]How to resolve Parsing Error: Missing semicolon?

I'm new to React and I'm trying to learn by building a book list web application.我是 React 的新手,我正在尝试通过构建图书列表 web 应用程序来学习。

When saving my code I'm getting the following in localhost:保存我的代码时,我在本地主机中得到以下信息:

Compiled with problems: ERROR src/Components/BookList.js Line 2:5: Parsing error: Missing semicolon.编译有问题:ERROR src/Components/BookList.js Line 2:5: Parsing error: Missing semicolon. (2:5) (2:5)

There is the BookList.js File:有 BookList.js 文件:

import React from "react";
import Book from "./Book";
import "./BookList.css";
import { BookContext } from "../context/BookContext";
import { ThemeContext } from "../context/ThemeContext";

export default class BookList extends React.Component {
  render() {
    return (
      <ThemeContext.Consumer>
        {(contextTheme) => (
          <BookContext.Consumer>
            {(contextBook) => {
              const { books } = contextBook;

              const { changeColorTheme, isDarkMode, dark, light} = contextTheme;

              const theme = isDarkMode ? dark : light;

              return (
                <section className="page-section" style={{ backgroundColor: theme.bg, color: theme.color }} id="portfolio">
                  <div className="container">
                    <div className="text-right"><button className="btn btn-danger" onClick={changeColorTheme}>Change Mood</button></div>
                    <div className="text-center"><h2 className="section-heading text-uppercase">My Book Folio</h2><h3 className="section-subheading text-muted">subheading</h3></div>
                    <div className="row">
                      {books.map((book, index) => {
                        return <Book book={book} key={index} />;
                      })}
                    </div>
                  </div>
                </section>
              );
            }}
          </BookContext.Consumer>
        )}
      </ThemeContext.Consumer>
    );
  }
}

I've looked through the code and I can't see the missing colon.我查看了代码,但看不到缺少的冒号。 My only other thought is that there's some other syntax error I haven't noticed.我唯一的另一个想法是还有一些我没有注意到的其他语法错误。

Does anyone have any idea or any recommendations on how to debug this?有没有人对如何调试有任何想法或建议?

I rewrote the code in the return statement and the web application worked.我重写了返回语句中的代码,web 应用程序运行了。 I've tried to compare the code, however, I can't see where the original issue was.我试图比较代码,但是,我看不到原始问题出在哪里。

Here is an image of the working code这是工作代码的图像

If you figure it out please let me know.如果你弄明白了,请告诉我。 As I would love to know what the cause was.因为我很想知道原因是什么。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM