编译失败,语法错误:缺少分号

时间:2021-05-19 16:09:54

标签: reactjs

我正在制作一个侧边栏,想使用一些 json 格式的数据,所以我制作了这段代码,但不知道我哪里错了。

这是我的代码:

    import React from 'react';
    import axios from 'axios';
    import { API_URL } from '../utils/constant';
    
    const Sidebar = ({show}) => {
        constructor(props) { //here is where i got wrong
            super(props)
        
            this.state = {
                 game:[]
            }
        }
        
        componentDidMount() {
            axios
              .get(API_URL + "game")
              .then(res => {
                const game = res.data;
                this.setState({ game });
              })
              .catch(error => {
                console.log("error lul", error);
              })
          }
    
          console.log("game : ", this.state.game);
    
        

顺便说一句,这个列表是我以前使用的弹出式侧边栏,我仍然把它放在同一个文件中

          return (
                <div className={show ? 'sidenav active' : 'sidenav'}>
                    <ul>
                        <li>
                            <a href='#home'>Dota</a>
                        </li>
                        <li>
                            <a href='#home'>Counter Strike</a>
                        </li>
                        <li>
                            <a href='#home'>Valorant</a>
                        </li>
                    </ul>
                
            </div>
        )
    }

export default Sidebar

1 个答案:

答案 0 :(得分:1)

我发现的第一个问题是您在功能组件中使用 DELETE FROM HERAPERM.SCRUBLITST WHERE COALESCE(iDate(ODUDAT,'*MMDDYY') , iDate(ODCDAT,'*MMDDYY') , current_date) > CURRENT_DATE - 2 ; , componentDidMount() 而不是类组件。将您的功能组件转换为类组件,反之亦然。如果转换为 class component,则必须扩展 constructor() 并添加 Component 方法。如果您转换为功能组件,则必须使用 react hooks

相关问题