Search code examples
reactjsspotify

'decodeUriComponent' is not defined no-undef


For some reason I'm getting an error saying 'decodeUriComponent'. The code is below to review it. First I thought I had to import decodeUriComponent but I could't find any information related that I need to import it. I went over about 30 minutes but I could't find anything that is causing this issue. I would highly appreact if anyone tell me what I need to do or what I need to fix in my code in order to fix this issue with React

Thank you

    // https://develoepr.spotify.com/
// documentation/web-playback-sdk/quick-start/#
export const authEndpoint = "https://accounts.spotify.com/authorize";
const redirectUri = "http://localhost:3000/";
const clientId = "xxxxxxxxxxxxxxxxxxx";

const scopes = [
    "user-read-currently-playing",
    "user-read-recently-played",
    "user-read-playback-state",
    "user-top-read",
    "user-modify-playback-state",
];

export const getTokenFromUrl = () => {
    return window.location.hash
    .substring(1)
    .split("&")
    .reduce((initial, item) => {
        let parts = item.split("=");
        initial[parts[0]] = decodeUriComponent(parts[1]);

        return initial;
    }, {});
}

export const loginUrl = `${authEndpoint}?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scopes.join("%20")}&response_type=token&show_dialog=true`;

Solution

  • It's decodeURIComponent (capitalized URI) not decodeUriComponent.