Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Missing semicolon in constructor (React + Spotify API)

I am following a youtube tutorial so I can use spotify’s api with my react app. This tutorial is from November 2017 so maybe the syntax has changed. I copied the code exactly but receive a "missing semicolon." error. Can anyone help me? I have tried adding a semicolon in various places throughout the code but it doesn’t fix the problem.

My code:

import './App.css';

function App() {
  constructor(){
    super();
    const params = this.getHashParams();
    const token = params.access_token;
    if (token) {
      spotifyApi.setAccessToken(token);
    }
    this.state = {
      loggedIn: token ? true : false,
      nowPlaying: { name: 'Not Checked', albumArt: '' }
    }
};
  getHashParams() {
    var hashParams = {};
    var e, r = /([^&;=]+)=?([^&;]*)/g,
        q = window.location.hash.substring(1);
    while ( e = r.exec(q)) {
        hashParams[e[1]] = decodeURIComponent(e[2]);
    }
    return hashParams;
  }

   return (
    <div className="App">
      <a href='http://localhost:8888'>
        <button>Login with Spotify</button>
      </a>
      <div> Now Playing: { this.state.nowPlaying.name } </div>
      <div>
        <img src={ this.state.nowPlaying.image } style={{ width: 100}}/>
      </div>
      </div>
  );
}



export default App;

Error message:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Failed to compile.

./src/App.js
SyntaxError: /Users/manuelfiestas/client/src/App.js: Missing semicolon. (4:15)

  2 |
  3 | function App() {
> 4 |   constructor(){
    |                ^
  5 |     super();
  6 |     const params = this.getHashParams();
  7 |     const token = params.access_token;




>Solution :

I Believe this line is wrong, should be a class

function App() {

write this instead :

class App extends React.Component{ {

also import react if not already done (top of the file)

import React from 'react';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading