Jamming REACT (general question)

Why the original codecademy example of JAMMING which is here

Starts working after the second search click ?
I thought it was only my bug :roll_eyes:

1 Like

Hi Yves!
There is this thread here in the forum:

But I thought that this happens because acces token is not required until you click search the first time, which it could be solved by calling to search() when it loads the page, but don’t know how to do it, and I’m not sure this is the reason.
Anyway we may solve it while working in the next step Feature Request: Jammming

I’ve just open this thread on the forum to share our work

happy coding! :stuck_out_tongue_winking_eye:

1 Like

You can run an empty search the first time, which will reload the page and allow you to search with no problems. Knowing this, I chose to force an empty search automatically when the page loads by adding the following code to the App component:

 componentDidMount() {
    window.addEventListener('load', Spotify.search(''));

This has the added benefit of bringing up the login screen automatically when the page loads if you are not already logged in.


I found an easyer solution placing Spotify.getAccessToken(); in App.js just after the imports.
Thank you anyway.


Hello! The search triggers an event and you can use event.preventDefault() in your event handler.

Hope that helps!

Where exactly would you add the preventDefault? Because I’m trying everywhere and it doesn’t work.

Very useful! thanks :slight_smile: