<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Parth2412 on Medium]]></title>
        <description><![CDATA[Stories by Parth2412 on Medium]]></description>
        <link>https://medium.com/@parthnpatil06?source=rss-62ab2de060b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Parth2412 on Medium</title>
            <link>https://medium.com/@parthnpatil06?source=rss-62ab2de060b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:35:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@parthnpatil06/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Manage Dynamic and Custom Subdomains in React]]></title>
            <link>https://javascript.plainenglish.io/manage-dynamic-and-custom-subdomains-in-react-31154559694?source=rss-62ab2de060b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/31154559694</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Parth2412]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 09:57:51 GMT</pubDate>
            <atom:updated>2021-08-24T09:57:51.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1DB8m3n0OPxMi8Wy" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>How do websites such as <a href="http://hashnode.com/">hashnode.com</a> give a separate and custom domain for every user? For example, <a href="https://parth2412.hashnode.dev/">https://parth2412.hashnode.dev</a>. This question has always dazzled me. The way they do it seems like magic. Or at least that’s what I thought. This article guides you through managing dynamic and custom subdomains in a react app.</p><p>In this article, we will build a simple and minimalistic React app in which each user would have a custom subdomain based on their username and going to that subdomain would show the profile of the user, which will include the user’s age, name and hobbies. And going to the main domain will show the links to all the user’s subdomains.</p><p>For example, if a user has a username of <em>john</em> , age <em>15</em> and hobbies of <em>Football and Cricket,</em> then going to the url john.domain.com will show the name (&quot;john&quot;), age (15) and hobbies (Football and Cricket) of the user &quot;john&quot;, where domain.com is assumed to be the primary domain of our app.</p><p>The data for the users would be dummy data and not from the database.</p><h3>What is a subdomain?</h3><blockquote><em>A subdomain is an add-on to your primary domain name. Essentially, a subdomain is a separate part of your website that operates under the same primary domain name.</em></blockquote><blockquote><em>Your primary domain name could be “ </em><a href="http://bestwebdesigner.com/"><em>bestwebdesigner.com</em></a><em>,” while you could add a subdomain to that domain called “ </em><a href="http://blog.bestwebdesigner.com/"><em>blog.bestwebdesigner.com</em></a><em>.”</em></blockquote><blockquote><em>Subdomains give you the freedom of creating an entirely new website, while still using the same domain name. Plus, you can usually create an unlimited number of subdomains for every domain you own.</em></blockquote><p>Source: <a href="https://www.hostgator.com/blog/whats-a-subdomain/">https://www.hostgator.com/blog/whats-a-subdomain/</a></p><p>Go <a href="https://www.hostgator.com/blog/whats-a-subdomain/">here</a> for more information.</p><h3>Prerequisites</h3><ul><li>React basics (Hooks and Functional Components)</li><li>JavaScript basics (window object and array functions)</li><li>Basic knowledge about domains and subdomains</li></ul><p>Start by creating a React app.</p><pre>npx create-react-app dynamic-subdomains</pre><pre>cd dynamic-subdomains</pre><p>You can name your app whatever you want.</p><h3>How would you use subdomains on localhost?</h3><p>I thought using subdomains on <a href="http://localhost/">localhost</a> would require quite a bit of configuration. But I couldn’t be more wrong. For example, if your react app is running on <a href="http://localhost:3000/">localhost:3000</a> , then going to the URL john.localhost:3000 or jane.localhost:3000 or any other subdomain will still show your react app. No configuration needed.</p><h3>How can you show different content based on the subdomain in React?</h3><p>The following code is how we access the subdomain from the full domain using <strong>pure JavaScript.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8o3IhcLU663doVEN" /></figure><p>Let’s see what’s happening here</p><ol><li>We get the full domain of the app using window.location.host (Only the domain, not the full URL).</li><li>Suppose the URL is <a href="https://javascript.plainenglish.io/dear-developer-this-is-how-you-center-a-div-e526e7cfcc9d">https://javascript.plainenglish.io/dear-developer-this-is-how-you-center-a-div-e526e7cfcc9d</a> then the host will be javascript.plainenglish.io</li><li>We split the domain into an array wherever we find a . . The resulting array would be [&quot;javascript&quot;, &quot;plainenglish&quot; , &quot;io&quot;]</li><li>If the primary domain is <strong>not localhost</strong>, we remove the last 2 elements of the obtained array. The last element is the suffix of the domain such as .org, .com, .net, .io, etc. The 2nd last element of the obtained array would be the main (primary) domain of the app.</li><li>In the example, the last element of the array is the suffix io. The second last element is the primary domain plainenglish. Thus we are left with the array [&quot;javascript&quot;]</li><li>If the array has 0 elements then there is no subdomain. If not, the subdomain is the first element of the array. Thus the subdomain is javascript</li></ol><p>Another example for development where the primary domain is localhost</p><ol><li>Suppose the host (full domain) is sub.localhost:3000</li><li>After splitting the domain wherever we find a ., we get the array [&quot;sub&quot;, &quot;localhost:3000&quot;] .</li><li>Since the primary domain is localhost, it means that the domain doesn’t have a suffix such as .com or .org. So instead of 2 we just remove 1 element from the end of the array. Thus we are left with the array [&quot;sub&quot;]</li><li>If the array has 0 elements then there is no subdomain. If not, the subdomain is the first element of the array. Thus the subdomain is sub</li></ol><h3>Note</h3><p>Subdomains can be nested under many levels too i.e there can be multiple subdomains such as <a href="http://a.b.c.d.example.com/">a.b.c.d.example.com</a> . But this article will only focus on handling one level of subdomain.</p><p>Getting back to our react app, we will now see how the above code should be written in the react format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W2kj6brO7gjNwU6R" /></figure><p>The same thing’s happening here but instead of storing the subdomain in a variable we are storing the subdomain in React state, also we are extracting the subdomain in the useEffect callback.</p><p>Let’s add the dummy data for the users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*pqYb90tv07eoN34o" /></figure><p>Here we have an array of users.</p><p>Each user has a unique username , an age and a list of hobbies.</p><p>So when we go to the URL john.localhost:3000 , it will show the name, age and hobbies of the user &quot;john&quot;.</p><p>Thus the URL jane.localhost:3000 will show the name, age and hobbies of the user &quot;jane&quot;.</p><p>Thus in this app, each user will be assigned a subdomain (which will be equal to their username) and going to that subdomain will show the user’s name, age and hobbies</p><p>The next and last part is really easy. We just have to use the subdomain value stored in the state to display the appropriate content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4FT8kdbnBvGBmgUK" /></figure><p>As simple as that.</p><p>We get the subdomain and use that to find the user whose username is the same as the subdomain and store the user in the requestedUser variable.</p><p>If there is no user whose username is the same as the subdomain, then we display a text of <em>Not Found</em>. Else we display the name, age and hobbies of the user.</p><p>Here’s how it looks (I am using the port 3001 since port 3000 is already being used).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wmfoToE0t-FCFSUw" /></figure><p>Here’s how the website looks when the requestedUser is not found</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j4GmSP2FvI_Jha3d" /></figure><p>Let’s take it up a notch higher and make it such that there is no subdomain, i.e the when the user who is looking at the website, is on our main domain, then we display a link to all of the user’s subdomains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MELQ6qlJB-z1uq9f" /></figure><p>Here’s what’s happening:</p><ol><li>We check whether there is a subdomain or not.</li><li>If yes, then the requestedUser’s data is shown</li><li>If no, then a list of the links to all the user’s subdomains is shown</li></ol><p>Here’s how it looks on the main domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vR2DazqVVHMHucfD" /></figure><h3>Coming Next</h3><p>How to handle dynamic subdomains in a Next.js app.</p><h3>Configuring subdomains for production</h3><p>Most hosting providers allow to configure dynamic subdomains. And usually dynamic subdomains come free when buying a domain.</p><ol><li>Vercel: <a href="https://vercel.com/blog/wildcard-domains">https://vercel.com/blog/wildcard-domains</a></li><li>Netlify: <a href="https://docs.netlify.com/domains-https/custom-domains/multiple-domains/#branch-subdomains">https://docs.netlify.com/domains-https/custom-domains/multiple-domains/#branch-subdomains</a></li><li>Google Cloud: <a href="https://cloud.google.com/appengine/docs/flexible/go/mapping-custom-domains#wildcards">https://cloud.google.com/appengine/docs/flexible/go/mapping-custom-domains#wildcards</a></li></ol><p>Github repo: <a href="https://github.com/Parth-2412/Dynamic-Subdomains">github.com/Parth-2412/Dynamic-Subdomains</a></p><p><em>Originally published at </em><a href="https://parth2412.hashnode.dev/manage-dynamic-and-custom-subdomains-in-react"><em>https://parth2412.hashnode.dev</em></a><em>.</em></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31154559694" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/manage-dynamic-and-custom-subdomains-in-react-31154559694">Manage Dynamic and Custom Subdomains in React</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Generator Functions in JavaScript]]></title>
            <link>https://javascript.plainenglish.io/introduction-to-generator-functions-in-javascript-e587f5f53d76?source=rss-62ab2de060b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e587f5f53d76</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Parth2412]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 11:01:16 GMT</pubDate>
            <atom:updated>2021-08-06T11:01:16.274Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JlLqZRZVaKFbVt2p" /></figure><p>Generators are an advanced concept in JavaScript but are quite easy to understand. Generators are special functions in JavaScript which can return multiple values on demand, unlike regular functions which can only return one value.</p><p>Unlike normal functions, the execution of a generator function can be stopped <strong>midway</strong> and can be resumed.</p><h3>How to create a generator function</h3><pre>function* generatorFunction(){</pre><pre>}</pre><p>There is a special syntax for creating a generation function which is not much different from the normal function syntax.</p><p>The * after the function keyword is what makes this function a generator function.</p><h3>How to use the generator function created above</h3><pre>function* generatorFunction(){<br>  console.log(&quot;Start&quot;)<br>  yield 7;<br>  console.log(&quot;Midway&quot;)<br>  yield 8;<br>  console.log(&quot;Stop&quot;)<br>}</pre><pre>const gen = generatorFunction();</pre><pre>let result = gen.next();<br>console.log(result.value) // logs 7<br>result = gen.next();<br>console.log(result.value) // logs 8</pre><p>Another keyword yield is introduced here. You can think of yield as the return keyword but for generator functions. Let’s take an example here</p><p>Let’s see what’s happening here:</p><ol><li>We define a generator function which first yields (returns) the number 7 and then next yields the number 8. We also added a couple of console logs.</li><li>We call the generatorFunction here and store the return value in the variable gen</li><li>Normally when using normal functions you will expect the gen variable to hold the value 7.</li><li>But that’s not the case for generators. The gen variable doesn&#39;t store the value yielded by the generator, instead it stores a Generator object returned by generatorFunction</li><li>The gen object has a method next()</li><li>The first call of the gen.next() method starts the execution of the generator function and when it reaches a yield, it stops the function there and returns an object which has 2 properties value and done. <strong>Value</strong> is the yielded value and <strong>done</strong> is a boolean which tells us whether the generator function is done completely executing or not</li><li>So in the above example, when gen.next() is called for the first time, the generator function starts executing. &quot;Start&quot; is logged to the console and then the generator yields a value of 7. That&#39;s when it stops the function and returns an object, which (in this case) will be { value : 7 , done : false }. <strong>value</strong> is the yielded value which is 7. <strong>done</strong> is false because the generator is not completely executed yet; there are still some lines of code in the function yet to be executed. &quot;7&quot; is logged to the console.</li><li>The next (second) call of the gen.next() method resumes the generator function from the point it stopped at before. Thus, &quot;Midway&quot; is logged to the console and then the generator yields a value of 8. It stops the function there and returns { value: 8, done: false} since the yielded value is 8 and the function is still not done executing. &quot;8&quot; is logged to the console.</li><li>“Stop” is never logged to the console since we never call gen.next() again</li></ol><h3>Notes</h3><ul><li>In the above example, if we call gen.next() for a third time, “Stop” will be logged on the console and the object returned would be { value : undefined, done : true. Notice how this time the done property is true? That’s because all the code of the generator is done executing. Whereas the value property is undefined? That’s because no value has been yielded by the generator. If you keep calling gen.next() after this, the result will always be { value : undefined, done : true</li><li>A generator object cannot be restarted. Once it’s done completely executing, you cannot restart it. If you want to run a generator function again make a new Generatorobject by calling generatorFunction and store it in a new variable. Then you can work with that variable.</li><li>Example of the above point</li></ul><pre>const newGen = generatorFunction();</pre><pre>const newResult = newGen.next():</pre><pre>console.log(newResult).value) // logs 7</pre><p><em>Originally published at </em><a href="https://parth2412.hashnode.dev/introduction-to-generator-functions-in-javascript"><em>https://parth2412.hashnode.dev</em></a><em>.</em></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e587f5f53d76" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/introduction-to-generator-functions-in-javascript-e587f5f53d76">Introduction to Generator Functions in JavaScript</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Weird Syntax of `styled-components`]]></title>
            <link>https://javascript.plainenglish.io/understanding-the-weird-syntax-of-styled-components-405a36ffce23?source=rss-62ab2de060b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/405a36ffce23</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Parth2412]]></dc:creator>
            <pubDate>Fri, 14 May 2021 10:34:05 GMT</pubDate>
            <atom:updated>2021-05-14T10:34:28.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H7JyC1Ejlo9X8Oz5" /><figcaption>Photo by <a href="https://unsplash.com/@oskaryil?utm_source=medium&amp;utm_medium=referral">Oskar Yildiz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most of us get confused by the syntax of styled-components when we first try to learn it. When I first looked at it, I had many questions: How does it work exactly? Does it use some new JavaScript entity that I don’t know about? For example, let’s make a button which has red text.</p><pre>const Button = styled.button`<br>    color : red;<br>`</pre><p>What is ‘styled.button’ here exactly? Is it a new JavaScript entity? Turns out ‘styled.button’ is nothing other than a function. I was thoroughly confused when I found out it was a function. How did it work? That’s when I found out about <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates">tagged template literals</a></p><p>Styled components used tagged template literals. In JavaScript, when we pass a template literal as an argument to a function, we can omit the parenthesis. This feature is known as tagged template literals.</p><p>For example:</p><pre>function print(string){</pre><pre>    console.log(string.toString())<br>}</pre><pre>//normal function call<br>print(&quot;Hello World&quot;)<br>// logs &quot;Hello World&quot;</pre><pre><br>// function call with tagged templates<br>print`Hello World`<br>// logs &quot;Hello World&quot;</pre><p>Both the function calls are the same but the syntax is different. The second one is what we call tagged template literals.</p><h3>Conclusion</h3><p>This is how styled-components work and it is pretty easy to understand once we understand tagged templates. <em>I didn’t dive into tagged templates as it is a vast topic but this understanding should be enough to work with styled-components.</em></p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=405a36ffce23" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/understanding-the-weird-syntax-of-styled-components-405a36ffce23">Understanding the Weird Syntax of `styled-components`</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>