简体   繁体   English

React 语法错误 - 解析错误:意外的标记,

[英]React syntax error - Parsing error: Unexpected token,

 const Sidebar = () => ( <Stack direction="row" sx={{ overflowY: "auto", height: { sx: 'auto', md:'95%' }, flexDirection: { md: 'column' }, }} > {categories.map((category) => ( <button className="category-btn" style={{ background: category.name === selectedCategory && '#FC1503', color: 'white' }} key={category.name} > <span style = {{ color: category.name === selectedCategory? 'white': 'red', marginRight: '15px'}}> {category.icon}</span> <span style = {{ opacity: category.name === selectedCategory? '1': '0.8'}}>{category.name}</span> </button> ))}

In the end I get a Line 19:4: Parsing error: Unexpected token (19:4)最后我得到了 Line 19:4: Parsing error: Unexpected token (19:4)

Can't seem to understand what is wrong with the brackets on the last line, just started with React and checked this out, rewrote and edited it numerous times to no avail.似乎无法理解最后一行的括号有什么问题,刚开始使用 React 并检查了这一点,重写和编辑了无数次无济于事。

you need to wrap your component in single parent element which can be div or fragment, also need to close tag like or您需要将您的组件包装在可以是 div 或片段的单个父元素中,还需要关闭标签,如 or

const Sidebar = () => (      
      <div>
        <Stack
          direction="row"
          sx={{
            overflowY: "auto",
            height: { sx: "auto", md: "95%" },
            flexDirection: { md: "column" }
          }}
        />
        {categories.map((category) => (
          <button
            className="category-btn"
            style={{
              background: category.name === selectedCategory && "#FC1503",
              color: "white"
            }}
            key={category.name}
          >
            <span
              style={{
                color: category.name === selectedCategory ? "white" : "red",
                marginRight: "15px"
              }}
            >
              {category.icon}
            </span>
            <span
              style={{ opacity: category.name === selectedCategory ? "1" : "0.8" }}
            >
              {category.name}
            </span>
          </button>
        ))}
      </div>
    );

You forgot to close your properly.你忘了正确关闭你的。 2 possibibilities: <Stack>content</Stack> or <Stack /> 2 种可能性: <Stack>content</Stack><Stack />

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

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