Journey to my first React app
Tags: react, javascript, debug, beginners
Published: 2021-06-17 12:54:25

Building an app from scratch is much more than how it looks.
It is not that difficult. But for me, as a newbie, it is something difficult.
Let's divide my journey into three parts.
<ul>

<li>About the Project</li>
<li>Problems I faced and debugged</li>
<li>End</li>
</ul>


<h2>About the Project</h2>
<p>
We all have been looking for a place where we can sit and enjoy the music. After a hectic day, there is still a place where we can enjoy the peace. For some of us it's a Home, for some it's their loved ones.</p>

Quoting Jiraiya Sensei - <b>A place where someone thinks about you is a place you can call Home.</b>

<p>As we all have gone through a lot in this pandemic. So why not we just relax for a while and have a deep breath and just Relax.....</p>
<br />
<br />
<h2>Problems I faced and debugged</h2>
<p>At first, I thought of using the background as a component. But after including other components, they do not overlap. So I Googled this problem and came to know that there are two basic solutions
<ol><li>By using Overlay</li>
<li>By changing z-index</li></ol>
But I was unable to apply both the solution. So I came with a cringey solution i.e. by applying the image in CSS. Then I used <code>background-image : url(/xyz.jpg); </code> in my CSS.And now the components overlap as I wished. It worked fine but a new problem arrived at the same moment. The background image is zoomed to its maximum height and width. To overcome this , I wrote <code>background-size : cover;</code> which I think worked best for me.
Then I made a <code>Navbar</code> component. It worked fine:blush:.
Then after doing some more code , I thought of an idea:bulb:. Is that - Why don't I make the words coming on the screen more real that someone is typing that sentences? Then I Googled , and the library I used is <code>React Typist</code>. You can also try this on by going to the npm site.
I used that in my <code>Type</code> component. And by reading their documentation , I easily applied that on my App.
Then I put a <code>sound</code> component in my App. And the package I used is <code>react-audio-player</code> from [npm](https://www.npmjs.com/package/react-audio-player). And by applying some changes to the code, now I can see audio bar on my App. 

The problem now popped is that I wasn't able to add a URL to the player. I have downloaded a music file on my PC. It is in the same folder where my components are, but passing the file location to the URL is not enough to make the player work.</p><br>

>Programmers ability is - whenever they face any problem in their code. They Google.

And I did the same , some of them says "Use the location of the music as a variable and then use the variable in your code". Actually, it didn't work. :dizzy_face:
Spending some hours on this problem is making me more and more frustrated. Then I thought of using another package for the same. But I got stuck on the same problem until I realized the basic rule.<br />
>During the time of coding if you ever stuck in a problem for a long time. Just think from the start again and ask yourself the 5 W's and H. Then you will definitely find your way.

<br />
<p>So again, I did the same, fundamentally what I need - a URL, for what - for using it in my App. So I came with a solution. It might be a legal or illegal thing. I don't know. But a very simple solution i.e.<ol><li> just google "Download xyz mp3" or from wherever you can download, just go to that download link.:triumph:</li><li>Inspect that download link.</li>
<li>That's your URL.</li></ol>
![oie_xsTIxpyKijWW](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibjg9ttqrs5pxsz9st65.png)
Then after that everything seems fine. But the main problem is still waiting for me. I wasn't aware of that but it is waiting.....:hourglass_flowing_sand:

Back to my story,
As everything is working fine till now , So I thought of making my App responsive. Then I started working on <code>@media queries</code>. I wrote pretty well <code>@media queries</code>. After writing <code>@media queries</code> I was sure that this App is not made for portrait phones. Then I thought that why shouldn't I make a prompt that makes the user rotate his/her phone. After that, my brain cells start working on that thing. And again, the first problem arose, that is, my component isn't overlapping. Then I Googled the best way to ask a user to rotate his/her phone. But the answers are for React-native. I was working on React only. So after some more Googling, I came across a package that gets the orientation from the user.<code>use-window-orientation</code>. [Goto](https://www.npmjs.com/package/use-window-orientation)

Some of you might think - *"Ayo, why don't you just use <code>screen.height</code> and <code>screen.width</code> to get the pixels information and do this"* 
```
if (screen.width > screen.height ) {
    return landscape;
} else {
    return portrait;
}
```
Yes, I came up with that solution also, but that was after solving the problem.
So,
In the documentation they explained the use in some other way but I prefer a different technique. I use **Conditional Rendering**

```
const { portrait } = useWindowOrientation();
    if (portrait) {
        return <Rotate />
    }
    else {
        return (
            <div className = "Home">
                <Navbar />
                <Type />
                <Music />
            </div>
        )
    }
```
And that's the solution folks.



![you-can-do-it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03ut6x1d96l2qvq1rwi2.jpg)
 

<h2>End</h2>
I was so happy to tell my friend about this problem and I solved it. This is just a basic start of this project, I have many more things to do in this project. For some pro developers, these problems might not count in their problemsList. But I write this article for some newbies like me out there who are still struggling to find their way in their problems.
You can check my github repo for this project.

>The beginning is the end and the end is the beginning. 



Thank you folks for reading this article.

:point_down::full_moon_with_face: 
[GitHub-repo](https://github.com/shashannkbawa/relax)