如何解决解析错误:缺少半隆?

发布于 2025-01-26 05:41:05 字数 1920 浏览 1 评论 0原文

我是新手反应,我正在尝试通过构建书籍列表Web应用程序来学习。

保存我的代码时,我会在Localhost中获得以下内容:

汇编的问题:错误src/components/booklist.js第2行:5: 解析错误:缺少半隆。 (2:5)

有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'm new to React and I'm trying to learn by building a book list web application.

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. (2:5)

There is the BookList.js File:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2025-02-02 05:41:05

我在返回语句中重写了代码,并且Web应用程序有效。我试图比较代码,但是,我看不到原始问题在哪里。

这是工作代码的图像

如果您弄清楚了,请让我知道。我很想知道原因是什么。

I rewrote the code in the return statement and the web application worked. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文