将webpack和babel添加到我的项目后,Reactjs单击按钮不起作用

将webpack和babel添加到我的项目后,Reactjs单击按钮不起作用,reactjs,webpack,babeljs,Reactjs,Webpack,Babeljs,在添加网页前,此功能正常,添加后停止工作 export class Main extends Component { constructor(props) { super(props); this.state = { currentPage: states.allProducts }; this.handleClick = th

在添加网页前,此功能正常,添加后停止工作

export class Main extends Component { 
        constructor(props) {
            super(props);
            this.state = {
                currentPage: states.allProducts
            };
           
            this.handleClick = this.handleClick.bind(this);
            
        }
        async componentDidMount() {
            let currentPage = this.state.currentPage;
        }
       
        handleClick() {
            alert('a');
        }
        render() {
            return (
                <button onClick={this.handleClick}>
                    Say hello
                </button>
            );
        }
    }
导出类主扩展组件{
建造师(道具){
超级(道具);
此.state={
当前页面:states.allProducts
};
this.handleClick=this.handleClick.bind(this);
}
异步组件didmount(){
让currentPage=this.state.currentPage;
}
handleClick(){
警报(“a”);
}
render(){
返回(
打招呼
);
}
}

强烈建议使用create react应用程序。 它将自行设置和安装所有babel插件和预设,所以您不会面临这样的问题

如前所述

现在,createreact应用程序支持异步/等待开箱即用。但是,如果你有一个网页包样板,你可能会遇到一个错误(一分钟内会出现更多错误)


这是因为缺少一些babel插件,您可以安装它们,希望一切都能正常运行

状态对象中的消息键在哪里?但是如果我想更改网页包怎么办。配置,可以吗?可以,但您还必须安装其他软件包,如cra webpack config,