javascript - React componentDidMount "Parsing error: Missing semicolon" - Stack Overflow

"Parsing error: Missing semicolon".SyntaxError: clientsrcApp.js: Missing semicolon (15:21)T

"Parsing error: Missing semicolon".

SyntaxError: client\src\App.js: Missing semicolon (15:21)

This error is showing on ponentDidMount() line.

and the full code is given below.

import React, { Component } from "react";
import AppNavBar from "./ponents/AppNavbar";
import ShoppingList from "./ponents/ShoppingList";
import ItemModal from "./ponents/ItemModal";
import { Container } from "reactstrap";

import { Provider } from "react-redux";
import store from "./store";
import { loadUser } from "./actions/authActions";

import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";

function App() {
  ponentDidMount() {
    store.dispatch(loadUser());
  }
  return (
    <Provider store={store}>
      <div className="App">
        <AppNavBar />
        <Container>
          <ItemModal />
          <ShoppingList />
        </Container>
      </div>
    </Provider>
  );
}

export default App;

"Parsing error: Missing semicolon".

SyntaxError: client\src\App.js: Missing semicolon (15:21)

This error is showing on ponentDidMount() line.

and the full code is given below.

import React, { Component } from "react";
import AppNavBar from "./ponents/AppNavbar";
import ShoppingList from "./ponents/ShoppingList";
import ItemModal from "./ponents/ItemModal";
import { Container } from "reactstrap";

import { Provider } from "react-redux";
import store from "./store";
import { loadUser } from "./actions/authActions";

import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";

function App() {
  ponentDidMount() {
    store.dispatch(loadUser());
  }
  return (
    <Provider store={store}>
      <div className="App">
        <AppNavBar />
        <Container>
          <ItemModal />
          <ShoppingList />
        </Container>
      </div>
    </Provider>
  );
}

export default App;

Share Improve this question asked Apr 28, 2021 at 7:28 Waleed ur RehmanWaleed ur Rehman 1193 silver badges11 bronze badges 1
  • 1 ponentDidMount is used in class based React, you appear to be using Hooks, you can't mix them. – Keith Commented Apr 28, 2021 at 7:36
Add a ment  | 

1 Answer 1

Reset to default 5

Import useEffect:

import { useEffect } from "react";

... and replace:

ponentDidMount() {
  store.dispatch(loadUser());
}

with:

useEffect(() => {
  store.dispatch(loadUser());
}, []);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742360976a4429386.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信