DEV Community

Cover image for How I created A Spotify Clone App using React JS
Ibraheem Zafar
Ibraheem Zafar

Posted on • Edited on

How I created A Spotify Clone App using React JS

This guide provides a comprehensive step-by-step process of how I created a Spotify clone app using React. It covers everything from setting up the environment, installing necessary dependencies, and structuring the project to managing state with useReducer, integrating Spotify's API for fetching playlists and tracks, and implementing user authentication and authorization.

1 First of all for creating Spotify clone app We have to install node, then run npx create-react-app in terminal of visual studio code to make a react application.
2 Than we have to download all the dependencies like styled components, axios, icons.
3 Than we will render our app component inside root index.js.
4 Than we will make utils directory in src directory. Create stateProvider.jsx and reducer.js inside utils.
5 Inside stateProvider we will make a default initial state by using useReducer hook.
6 Inside reducer we will make a constant initialState having token with null value.
7 Make reducer constant for returning state.
8 Make sure to export all components and utils.
9 First of all we will make a new folder inside src named components. Then we will first make login.
10 React components which will make the main page for our website which will authorize us with Spotify.
11 It will use handleClick function to store all authorization gained by developer.spotify to access.
12 Spotify API. First we will use GET USER PLAYLIST web API from dev.spotify by using API URL and headers.
13 Adding them to our playlist component later on.
14 Than we will make a constants file in utils to declare SET_TOKEN constant after rendering it in app.js.
15 Then we will make a spotify.jsx component which will be the main structure holder of our web app.
16 Then we will make all other components body, footer, sideBar, navbar and render them like wisely in spotify.jsx component. Then we will fill out the components and export so they are functional.
17 Note: we will be using CSS at the bottom using styled according to our expectations.
18 Then after making our main components we will make a playlists.jsx component to display our playlists and then to choose and see tracks in it. We will use useEffect and axios to get playlist data after using state provider on token and dispatch, we will add API link to get playlist in component. Then we will update SET_PLAYLIST constant and add new reducer case of SET_PLAYLISTS.
19 Remember to use Login.jsx as an authorization component for main Spotify app.
20 Then in spotify.jsx we will add a new constant to get user info API which will retrieve ID and name.
21 Then add USERINFO constant and define initial state and reducer case in reducer.jsx.
22 Then we will update our navbar to have a search option to filter results and style it.
23 Then inside body we will use state provider first for showing selected playlist. Then use useEffect.
24 To link fetched playlist ID inside a constant. Then we will set our Spotify playlists on our clone app front by calling getCurrentPlaylist.
25 Body component will also maintain and track selected playlist. Then we will add SET_PLAYLIST constant to constants list in constants.jsx. Then in reducer.js we initialize selected playlist and use reducer case for SET_PLAYLIST. In short body.jsx will track all our playlist data from Spotify to clone app.
26 Than we will make current track component which will track what track is currently playing. Using useEffect and get CurrentTrack constant which will fetch and store value from currently playing API.
27 Store it in constants.jsx and define a reducer case for it in reducer.
28 Now we will make playerControl component which will first import all icons and then set SETPLAYER_STATE in constants.js. Its main function is to render JSX on next, pause, and previous buttons and perform or post specific actions accordingly. It is posting instead of getting. It will use different APIs and multiple dispatch.
29 Than at last we will add SET_PLAYLIST_ID constant in constants.js, reducer case in reducer.js and dispatch in playlists through constant changeCurrentPlaylist.

Link to Github: https://github.com/Devibbi/spotify-clone
Link to Spotify-Clone : https://spotify.devibbi.com/
I am Front End Developer and certified engineer from code academy. Know more about me on:
Link to my Profile: https://devibbi.com/

Top comments (0)