<?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 Sean LaFlam on Medium]]></title>
        <description><![CDATA[Stories by Sean LaFlam on Medium]]></description>
        <link>https://medium.com/@laflamablanc?source=rss-175b874719d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U4oRfj4VUoaDdbfOCZuZWQ@2x.jpeg</url>
            <title>Stories by Sean LaFlam on Medium</title>
            <link>https://medium.com/@laflamablanc?source=rss-175b874719d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:52:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@laflamablanc/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[Spotify Bull Thesis]]></title>
            <link>https://laflamablanc.medium.com/spotify-bull-thesis-ce178e75aca0?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce178e75aca0</guid>
            <category><![CDATA[stock-trading]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[spotify]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[technology-news]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Tue, 16 May 2023 01:12:19 GMT</pubDate>
            <atom:updated>2023-05-16T06:29:53.182Z</atom:updated>
            <content:encoded><![CDATA[<h4>How an incredibly sticky app and pivot into podcasting have set this company up for massive profitability</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWAfyD9_oglk0ojbXfrbZA.png" /></figure><h4>What Are the Best Businesses To Be In?</h4><p>My personal opinion is that two of the best business models ever created are software companies and media companies. Why? Well, both are extremely scaleable and easily distributable. Once a piece of software is created, or a piece of content is recorded, it can be distributed digitally across the entire globe at virtually no incremental cost. You don’t have to worry about logistics, supply chain problems, inventory expiring or any of the problems that come along with shipping “atoms”.</p><p>That brings us to Spotify. What’s better than a software company or a media company? <strong>How about one that’s both.</strong></p><h4>What Is the Most Valuable Real Estate In the World?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*MmFbhzOoGmaU-Em4PfF0DQ.jpeg" /></figure><p>According to Google it’s Buckingham Palace. To make this piece of real estate yours you’d either have to fork over an estimated $4.9 Billion <a href="https://www.youtube.com/watch?v=RvzpuAa1QVs">or marry the Queen</a>.</p><p>But Google is wrong.</p><p>The real answer to that question is the fixed bar of apps at the bottom of your iPhone/Android shown here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTJsEqG04sZTTOaDE1SKgQ.jpeg" /></figure><p>As you can see, mine contains my texts, my email, my web browser and Spotify. So how much is this real estate worth? Let’s use a similar example to try and come up with an estimate.</p><p>In 2020 Google paid Apple $10 billion dollar to be the default search engine on all iPhones. That’s a whopping sum of money but analysts predict it was even higher in 2021 at around $15 billion and <a href="https://9to5mac.com/2021/08/25/analysts-google-to-pay-apple-15-billion-to-remain-default-safari-search-engine-in-2021/">may even have reached $20 billion in 2022</a>. It’s even crazier when you realize Google is paying that much only to be the default for the Safari browser when users can still download Firefox, Opera, or even Edge AND users can easily change the default Safari search engine in their settings. Still, Google feels like the exposure and increased search traffic is easily worth this steep price tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*5yVDhnvU6VRrmTKFtFTftA.png" /></figure><p>So what could Apple get if it sold the space at the bottom of all out of box iPhones so that an app such as Spotify would be automatically down there post-setup? I think it’s pretty reasonable that it could fetch a fee of around $5 — $10 billion to own one of those slots. But Spotify is doing this for WAY cheaper currently.</p><p>For the sake of this thesis I asked 25 of my friends and family who I knew were Spotify users if they had Spotify as one of the fixed apps in that bottom row. 9 of them told me they did. Obviously thats not statistically significant data but that response rate was MUCH higher than I anticipated and my theory is that this brand loyalty and stickiness is key to the future success of Spotify.</p><h4>Spotify is in the Habit Creation Business</h4><p>Humans are creatures of habit. Once we get into a routine it is very hard to break that. Spotify’s main goal right now is to increase the minutes users spend in their app so that it becomes an even stickier product and ultimately so that it has more data on us. One of the best ways to do this is to be featured prominently on a device that the average <a href="https://techjury.net/blog/how-much-time-does-the-average-american-spend-on-their-phone/">American picks up 63 times per day and uses for more than 5.4 hours daily.</a></p><p>Another metric to show Spotify’s stickiness is this quote from the Q1 2020 Shareholder letter:</p><p><em>“We also know that roughly 70% of churned users are back with Spotify within 45 days of leaving, which includes coming back through either our Premium or Ad Supported experience.”</em></p><p>That is a pretty incredible stat that makes Spotify’s actual churn rate effectively 1/3 as high as the reported number since most of the churned users are back by the next quarter.</p><p>Once they have you, Spotify is pretty confident you won’t leave or even look for other options.</p><h4>So How Does Spotify Become Profitable?</h4><p>I know what you’re thinking. “Yea, yea this is all good but at the end of the day a business needs to make MONEY and Spotify is good at doing the exact opposite”. I hear you. I actually thought the same when I first started writing this thesis. However, I realized upon a deeper look that for them to be doing anything besides growing as fast as possible and spending money to do so would be a complete failure by management to capture the opportunity in front of them.</p><p>There are 3 main ways that Spotify is currently set up to flip the profitability switch:</p><ol><li>Pricing Power</li><li>Ad-Supported Business Growth</li><li>Margin Improvement</li></ol><h3>Factor #1: Pricing Power</h3><p>Fun fact. Spotify has NEVER increased its price for its Premium subscriptions since its introduction in the US in 2011.</p><p>This means accounting for inflation Spotify has technically lowered its price every year by keeping it at this fixed rate. As the purchasing power of the dollar has decreased by roughly 34% over that time ($1 in 2011 is roughly $1.34 today) Spotify has not budged its price even slightly. As the saying goes, death, taxes, and Spotify Premium costing $9.99</p><p>So what would happen if Spotify were to increase its prices and how much can they do so before the churn rate makes it not worthwhile to do so. My estimate is they can do so by <strong>30% over the next decade </strong>to achieve the maximum revenue possible from subscriptions.</p><h4><strong>Where did this number come from if Spotify has never increased prices?</strong></h4><p>While Spotify has never increased prices in the US, they have in markets such as UK, Ireland and Norway which shows they are willing to do so in regions which they consider “fully saturated”. Unfortunately, Spotify doesn’t break out the churn by region only reporting the overall rate.</p><p>Below is a chart showing Spotify’s churn rate each quarter as reported in their Quarterly Shareholder Letters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*UeeH_Ru0HcZXqwo0ClMgjw.png" /></figure><p>Its been steadily decreasing reaching a flatline Annualized Churn Rate of about 15.6% at the end of last year.</p><p>So let’s see how this compares to similar company. Below is the monthly chart for Netflix showing price increases and their effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zEJn6DBWhJoc898e.png" /></figure><p>This graph shows the three price increases for Netflix ($1, $2, and $1.50 respectively) and their impact on the churn rate afterwards.</p><p>Taking the average churn rate increase and then taking into account the dollar amount of the increase, it appears that a $1 increase in price results in a roughly 25% increase to the churn rate over the next quarter. As you can see, however, the effect pretty quickly subsides. This should give us a solid relative comp to estimate the impact of Spotify increasing prices and find the point where too steep a price increase hurts overall revenue due to lost customers.</p><h4>The Math</h4><p>First, we need to figure the Average Revenue Per Premium User. Luckily, this is a number Spotify gives us directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*yL9mBGNgOE67u79fLBubwg.png" /><figcaption>Converting to USD yields $4.94 (May 2023)</figcaption></figure><p>What they don’t give us, however, is how this number is broken down between Spotify’s four plans: Individual, Duo, Family, and Student, which all have different prices and number of users per plan.</p><p>To estimate the impact of a $1 increase to each of these plans on the ARPU number, I had to come up with a reasonable estimate for the breakdown of these plans. This is what I came up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ve9Tspv9MDDvS9Tp1ADahw.png" /></figure><p>Setting up our model so that each $1 increase in price increases our churn rate by 25% and then also factoring in that 70% of those users reportedly return by the next quarter, we are able to use the Solver function in Excel to find the price increase that maximizes Revenue through 2030. That number would be an increase of $3.10 or 31% versus current prices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k5tMsNz2eh2hUlf0Pq-ciA.png" /></figure><p>Since we want to keep the numbers round, we will say that a $3 increase is the optimal price increase. To minimize the effect on the consumer, we will also assume the price increases are broken up into three separate raises of $1 each over the next decade. This gives us the following predicted churn graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4U3z1YE0epqxyQJyzoI32w.png" /></figure><p>Increasing prices in such a manner will allows Spotify to capture the revenue growth potential from raising prices while minimizing the number of users who leave the platform as a result. Assuming that the price raises are uniform across each plan, each $1 increase in price will increase the Average Revenue per User by $0.49. At the end of the 3 increases we will have the following ARPU:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rnTXeo93qJfIlN6bXEgOHw.png" /></figure><p>Factoring in ARPU increases, projected growth rates, and the effect of price increases on those growth rates allows us to make the the following forecast for Spotify’s revenue through 2030</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1kQq3UomQNpss3EacAwW6Q.png" /></figure><p>Hopefully you can zoom in to read that but if not, our model is predicting 463 million Premium subscribers and $30.1B in revenue from Premium by 2030 which would be a CAGR of 17.8% and a 150% increase from current Premium revenue. This presents pretty significant upside for the company and its stock price.</p><h3>Factor #2: Opportunity in Ad-Supported Business</h3><p>There is a three-pronged approach to the opportunity Spotify is viewing in the Ad-Supported part of their business:</p><ol><li>Grow Users through Ad Supported Tier</li><li>Improve Ad-Supported Margins</li><li>Increase Time Spent on App (Through Podcasts &amp; Audiobooks)</li></ol><h4>Grow Users</h4><p>As I mentioned before, Spotify has been prioritizing growth at all costs but they are starting to hit peak saturation in some of their mature markets. Don’t believe me? Then look at this chart Spotify released themselves</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*xUW45W7jqsB6TQ17Bc0SyA.png" /></figure><p>Here in North America, and in Europe, Australia, and its home region of the Nordic countries Spotify has already begun to reach peak saturation and adoption so growth potential through new users is limited. However, there is still a massive opportunity to grow users in some of the emerging markets such as Asia, the Middle East, and Africa where not only is music streaming still in its infancy, Spotify itself doesn’t have much of a presence there.</p><p>Since users in these territories are much more price sensitive than in the established markets, the main way Spotify will try to onboard new users is through its ad-supported “free” plan with the hopes of later converting them to higher margin Premium customers.</p><p><strong>The model expects a 19.6% CAGR for the Ad-Supported Business which will grow even faster than the Premium business resulting in 674 Million MAUs by 2030.</strong></p><h4>Improve Margins</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15CS6ZE_ygKtXap2slFHdQ.png" /></figure><p>From Spotify’s latest earnings report you can see they are operating at a healthy 25.2% gross margin overall, but the Ad-Supported margin is actually negative and has been for Q1 of three of the last four years.</p><p>Now a pessimist may say that’s bad because of the whole making money thing, but me, the eternal optimist, is here to say “What a huge opportunity for improvement!”. And improvement is not only a possibility but a likelihood. Here’s why.</p><p>First, you can see in the footnote that the profitability of the ad-supported music and podcast segments actually increased year over year which just happen to be the two most important things for the Ad-Supported segment. Podcasting boasts even higher margins than music so this should only continue to improve as more users start listening to their podcasts on Spotify.</p><p>What really hurt them is an increased Cost of Revenue which is from an increase in marketing and promotional expenses as well as paying for exclusive content. However, these are temporary expenses that play right into my first point about Spotify changing people’s habits now to reap the benefits in the long term. If you can convince people to stop using Apple Podcasts or some other service and start listening to the Joe Rogan experience on Spotify, then even after the exclusivity runs out they are likely to stay on the platform unless someone else pays to make that content exclusive on their platform. It also get people in the habit of opening Spotify more which in turn which should help the music business and audiobook business as well as people start to see Spotify as not only a music streaming platform, but a primary source of entertainment when they have some free time. I think this is overall a very good use of money by Spotify as it will set them up well in the long term.</p><h4>Increase Time Spent on App</h4><p>A major part of this thesis relies on Spotify’s ability to increase the time each user spends on the app, especially in the Ad-Supported plans, and become the major destination for audio entertainment.</p><p>According to a <a href="https://www.businessofapps.com/data/spotify-statistics/">report by Business of Apps,</a> the average daily usage time by each Spotify user in the US went from 124 minutes in 2020 to 140 minutes in 2021, good for a growth rate of 12.9%. Using a very conservative CAGR of 6.2% and projecting it out to 2030, we arrive at 240 minutes per day on the app in the US. This may sound like a lot but as Spotify continues to carve out more of the podcasting market and also adds more entertainment options such as audiobooks this should become a reality. Additionally, the average time spent watching TV in the US has been steadily declining as people tend to prefer entertainment option that allow them to multitask (listening to a podcast at work or an audiobook while cleaning) so the industry trends tend to agree with this prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*s0jUaLkZHwsvioPnsi_HtA.png" /><figcaption>6.2% CAGR through 2030</figcaption></figure><p>The average American reads less than one book per year, but that very well could be due to the fact that we have already shifted to an audiobook and podcast world for our information and Spotify is very aware of this and well-positioned to capitalize on this trend in the US and will likely see similar results in many other countries around the world.</p><h3>Factor #3: Cost Structure Improvement</h3><p>As discussed briefly earlier the Premium segment of the business operates at around a 28% gross margin but the Ad-Supported business loses money. While its pretty reasonable to assume the Ad-Supported business will start turning a profit as they lower their Cost of Revenue, I think there is still plenty of opportunity to increase gross margins in the Premium Business as well.</p><p>First, as Spotify is still the largest player in the music streaming market by a wide margin, they have a ton of bargaining power with labels to renegotiate royalty deals. Currently, 70% of revenue from streams goes to music rights holders (labels, producers, artists, etc) and Spotify only keeps 30%. This number scales with number of users and even with the potential price increases mentioned earlier. As a result, while price increases and more users can increase profits, they won’t really matter for margins with costs directly scaling. I believe that Spotify can renegotiate these terms in the future as labels now need Spotify more than Spotify needs them. In fact, I believe it is much more likely that Spotify could create its own label and block out the middle man in the near future than it is for labels to pull their music from Spotify. The latter would be incredibly damaging to all parties involved as it would cut out about 1/3 of all music streamers in the world with a much lesser effect on Spotify.</p><p>In the June 2022 earnings call, Spotify CEO Daniel Ek stated that by 2030 they plan on achieving a 40% gross and 20% operating margin in the overall business and project over 1 Billion monthly active users. For the base case, this MAU projection is actually inline with ours but we didn’t quite get to the 40/20 number instead getting to 32% and 12% (gross and operating respectively). Still, even with less than projected margins <strong>the model predicts Net Income of $1.9B in 2030 and $4.1B in 2031</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*osL9lKaxm8CMIYPNZCtV3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0b1s8g6aJt7ncSU7D-iL4g.png" /></figure><p>If we were to plug in the 40% and 20% for the extreme bull case those profits balloon to $4.3B in 2030 and $8.4B in 2031.</p><h4>Biggest Challenges</h4><p>One of the largest challenges has always been and will continue to be competition in the space. People will say that music is a commodity, and that Spotify doesn’t have any significant moat. They say eventually competition will begin to eat into their market share, however, year after year Spotify continues to defy these critics. As more and more competitors such as YouTube Music or even Amazon enter the conversation, Spotify continues to hold its 30ish percent market share.</p><p>Here is a nice chart showing that these new players tend to cannibalize each other while Spotify remains largely unaffected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*xpl6D9CLSCr9o7YC-Zkbxw.png" /></figure><p>In Q1 2023, Spotify just reported a MAU growth of 22% year over year which significantly outpaced the growth of the streaming industry and shows Spotify still is going to continue to dominate the market for the foreseeable future.</p><p>One legitimate worry that I have though is the potential for TikTok to enter the music and audio content game. They are the one player who I believe has both the attention from Gen Z and Milennial users as well as the proven algorithmic based recommendations to become a threat to Spotify in the future.</p><p>Another worry I have is that the Cost of Revenue just never comes down in a significant matter and that Spotify has to keep spending as they have been to retain this market share and attract new users and new content creators. If this happens, obviously the margin improvements which our valuation depend very heavily on would be inaccurate.</p><h3><strong>Conclusion</strong></h3><p>TOO MANY SPREADSHEETS AND WORDS. GIVE ME A PRICE TARGET DAMN IT!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*otTfMTM4z86VUbkr4gtC8Q.png" /></figure><p>Spotify has a tremendous opportunity in front of it to capitalize on potential price increases, ad-based listening through music and podcasts, and potential operating margin improvements.</p><p>The stock price has already been on a pretty solid tear since first beginning this research back in March, but I believe it still has a good amount of room to run in our Base Case valuation and in the Bull Case it can more than double.</p><ol><li>Bull Case — $336 per share (10% chance)</li><li>Base Case — $158 per share (80% chance)</li><li>Bear Case — $35 per share (10% chance)</li></ol><p>Using a weighted average of all three scenarios and our projected likelihood gives a Price Target of $164 per share</p><p><em>Obligatory Disclaimer:</em></p><p><em>Please note that the views and opinions expressed herein are solely my own and do not constitute financial advice. They are provided for informational and discussion purposes only and should not be relied upon as a recommendation to buy or sell any particular security, commodity, or financial product. I am not a financial advisor. Investing in stocks, commodities, and other financial products involves a high degree of risk, and you should consult with a qualified professional before making any investment decisions. Always do your own research and consider your own risk tolerance and financial situation before making investment decisions.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce178e75aca0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Evolution of Machine Learning at Spotify]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://laflamablanc.medium.com/the-evolution-of-machine-learning-at-spotify-ef16facb59ba?source=rss-175b874719d4------2"><img src="https://cdn-images-1.medium.com/max/2279/1*SafJkJj6BVpnUwQJV85aFA.png" width="2279"></a></p><p class="medium-feed-snippet">Background</p><p class="medium-feed-link"><a href="https://laflamablanc.medium.com/the-evolution-of-machine-learning-at-spotify-ef16facb59ba?source=rss-175b874719d4------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://laflamablanc.medium.com/the-evolution-of-machine-learning-at-spotify-ef16facb59ba?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef16facb59ba</guid>
            <category><![CDATA[collaborative-filtering]]></category>
            <category><![CDATA[spotify]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 23:55:42 GMT</pubDate>
            <atom:updated>2023-01-31T23:55:42.009Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to Web Scraping Using Python]]></title>
            <link>https://laflamablanc.medium.com/a-beginners-guide-to-web-scraping-using-python-d46c08a776af?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d46c08a776af</guid>
            <category><![CDATA[beautifulsoup]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Sat, 26 Nov 2022 07:12:57 GMT</pubDate>
            <atom:updated>2022-11-26T07:18:45.886Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Learn what web scraping is and see some of the best tutorials for Python web scraping</em></p><p>Python is a versatile language that can be used for a variety of purposes, one of which is known as web scraping. In this blog post, we will explore some of the best tutorials on web scraping using Python.</p><p>Web scraping is the process of extracting data from websites, whether it be costs of various products for price comparison, or email addresses for employees at a company, or even scraping social media for sentiment analysis on a certain topic. This can all be done manually, but more often than not, it is automated using tools like Python which are able to aggregate data on a much larger scale and do it near instantaneously.</p><p>There are many different ways to extract data from websites with Python, so we will look at tutorials for both beginners and more experienced users. Whether you are just getting started with web scraping or you are looking for more advanced techniques, we have something for you in this blog post!</p><h4>How Does Web Scraping Work Exactly?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*7h9SN1ZvORTi-P_ldEznHg.jpeg" /><figcaption>Scraping is the act of extracting data from a webpage for some other purpose</figcaption></figure><p>When you run the code for web scraping, a request is sent to the URL that you have mentioned. As a response to the request, the server sends the data and allows you to read the HTML or XML page. The code then, parses the HTML or XML page, finds the data and extracts it.</p><p>To extract data using web scraping with python, you need to follow these basic steps:</p><ol><li>Find the URL that you want to scrape</li><li>Inspecting the Page</li><li>Find the data you want to extract</li><li>Write the code</li><li>Run the code and extract the data</li><li>Store the data in the required format</li></ol><h4>Beginner’s Guide</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQhD015WUMxE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQhD015WUMxE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQhD015WUMxE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/090b55a2d964cf57f5c15adaa0ad8722/href">https://medium.com/media/090b55a2d964cf57f5c15adaa0ad8722/href</a></iframe><p>Check out the video above from Tinkernut and you can write a basic scraper in under 10 minutes of work. I highly recommend going through the process if you’re a beginner or even a more experienced programmer who is a little rusty.</p><h4>Moderate Experience</h4><p>Once you’re a little big more familiar with scraping you can start adding more specific skills such as scraping from multiple pages. The tutorial Below will walk you through that</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxVh0H3R9a2Y%3Flist%3DPLLfIBXQeu3aagYWxmBJNSvus79U69lV3I&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxVh0H3R9a2Y&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FxVh0H3R9a2Y%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d70e170ad783fe75c4bd712d83b47e67/href">https://medium.com/media/d70e170ad783fe75c4bd712d83b47e67/href</a></iframe><p>Another really neat trick is using Python to scrape a PDF instead of a website. The tutorial below will walk you through that.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYGt8WN6WUOM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYGt8WN6WUOM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYGt8WN6WUOM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/386d1bd275661ab57274b2fb11942de3/href">https://medium.com/media/386d1bd275661ab57274b2fb11942de3/href</a></iframe><h4>Advanced Web Scraping</h4><p>Finally, once you’ve mastered everything above, try to seek out more niche skills such as scraping a very specific format of website that may behave different than a standard HTML/CSS website you’re used to. A good example is a dynamically loading page. Check out the tutorial below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8Uxxu0-dAKQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8Uxxu0-dAKQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8Uxxu0-dAKQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d09c98ef9d6356eedd74dbe09a8ccaf/href">https://medium.com/media/7d09c98ef9d6356eedd74dbe09a8ccaf/href</a></iframe><p>I will update this blog as I find more great tutorials. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d46c08a776af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Meaningful Charts in Amplitude]]></title>
            <link>https://laflamablanc.medium.com/creating-meaningful-charts-in-amplitude-34b635a2e3ea?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/34b635a2e3ea</guid>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Wed, 23 Jun 2021 18:58:48 GMT</pubDate>
            <atom:updated>2021-06-23T19:57:13.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*anFA5AMUyscKOaJU6plehw.png" /><figcaption>Source: <a href="https://help.amplitude.com/hc/en-us/articles/115001816407-Amplitude-s-charts-find-the-right-one-for-your-analysis">https://help.amplitude.com/hc/en-us/articles/115001816407-Amplitude-s-charts-find-the-right-one-for-your-analysis</a></figcaption></figure><p>Recently, I have been working on more analytical side of web development, and have really been trying to understand what drives different user behavior.</p><p>Specifically, I have been focusing on one question that I find extremely interesting:</p><p><em>“Which user action is more correlated to user retention at the 1–months and 3-month marks?”</em></p><p>So basically, what behavior that a new user partakes in is most indicative of their long term retention? Is there a certain action that users perform in the first session after account creation that is a clear indicator that they will be users for the long haul? If so, how can we encourage more users to take this action so that we can increase retention overall?</p><h4>What Amplitude is Used For</h4><p>If you’re not familiar, Amplitude is a great analytical platform that allows you to perform event tracking and user behavior analysis. My company has added it to it’s React web and mobile apps in order to anonymously track things such as user sign up activity from marketing events, daily, weekly, and monthly active users, number of posts and comments per user, and a multitude of other useful data.</p><p>Right now, our 1-month and 3-month user retention rate is lower than we had hoped. This led to us deciding to do a deep dive to see what causes the users that do stick around to keep using the app, and see if we can encourage more users to follow suit. Here is how you can use amplitude to track events and try and deduce this information.</p><h4>Creating a Chart</h4><p>The first thing you’ll want to do is make sure event tracking is added to your web or mobile application. I already wrote an <a href="https://javascript.plainenglish.io/adding-analytics-to-your-react-application-b584265f9fae">article describing how to get started with this in React</a>.</p><p>Once that is done, you’ll want to navigate to your dashboard and press the New button to create your first chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZtQoJvtbb6iQEyRwG90xDg.png" /><figcaption>Select New then New Chart</figcaption></figure><p>Next, you’ll want to choose the events to track in order to form your chart. Here is an example of what yours may look like, but they will all be created by adding code to your application that tracks each event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DP0_DfpLDHt5FIAnMnJFKw.png" /><figcaption>Track things such as messages requests, clicks, joining a group, adding to a group, bookmarking a post etc.</figcaption></figure><p>Without showing you too much of the specifics of our user stats going forward, I will try to explain how to build a proper chart and extract useful data from it.</p><p>Let’s say you have a messaging board app. One interesting thing to chart would be the numbers of users that make a post, versus the number of users that reply to a post. In a healthy app, you would ideally be getting lots of replies on each posts, but it could also be interesting to look at how many people are doing both of these behaviors versus strictly replying.</p><p>You can also monitor how many users are “lurkers” who read posts without interacting and are more content consumers than creators.</p><p>In our case, the number of posts and post replies are pretty even, which can be from one of 2 things:<br>1) Power posters who create a lot of different posts without responding to other people’s</p><p>2) Low engagement rates on posts where you are only getting 1 or 2 replies to posts.</p><p>In our case, we actually seem to be skewing towards the former, where we have a lot of engagement on posts, but there are a strong contingent of people who posting daily and don’t really engage with others, so this is skewing the numbers toward even on posts vs post replies. We are coming up with a plan to encourage engagement on other people’s posts by these power users as I write this.</p><h4>Gleaning Insights from Charts and Tables</h4><p>Now you know how to set up event tracking and you know how to create charts and tables, but how can you figure out how to gain meaningful info from all these fancy graphs?</p><p>You want to begin by asking yourself a question and then trying to answer it using Amplitude’s tools.</p><p>In my case, i’ll refer back to the inspiration for this article:</p><p><em>Which behavior is the most clear indicator of long term user retention?</em></p><p>This is a very complicated question, but in our example case I will only use 2 behaviors:</p><ol><li>Creating a post</li><li>Sending a DM to a user</li></ol><p>What you want to do here is set up tracking for each of these events and then chart it against the user retention at various intervals. In our case we will use 1 month of data, but in your case you may want to extend it to a longer timeframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vq9AqMNkO9XRmEPlN0t0kw.png" /></figure><p>This chart depicts the user retention rate at each point for users after making their first post. After 1 day, there is a steep drop off for users that are still posting after making their 1st. Also, it shows that around 20% of people who make a post are also sending DMs at the time. It would appear that only 18% of people who make a post are still active at the 1 month mark.</p><p>Conversely, here is the chart when you use a DM as the trigger:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RySTmvh5VtL5G5CXd-yUxw.png" /></figure><p>It appears even fewer people who send a message request are still making posts at the 1 month mark, while the sending of DMs actually picks up towards the end.</p><p>This is a very simple concept, but gives an idea of what you can do with Amplitude, and when you add it to your app you can start answering these type of questions to see which actions lead to certain results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34b635a2e3ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a Higher Order Component?]]></title>
            <link>https://medium.com/geekculture/what-is-a-higher-order-component-204f0cd7bcfb?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/204f0cd7bcfb</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[higher-order-function]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 17:52:54 GMT</pubDate>
            <atom:updated>2021-06-23T03:19:36.388Z</atom:updated>
            <content:encoded><![CDATA[<p>A detailed explanation of React’s system for reusing component logic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aYNIzpcpn0Dkl3sNvo6SQ.png" /><figcaption>Bruce Wayne is enhanced by his Batsuit like a Higher Order Component enhances a normal component (Source: <a href="https://chrisnolan.fandom.com/wiki/Bruce_Wayne">https://chrisnolan.fandom.com/wiki/Bruce_Wayne</a>)</figcaption></figure><p>Have you ever been working in a codebase or been watching a tutorial online and come across something that looks like this:</p><pre>export default withResponsive(Home)</pre><p>Well then you already have encountered a Higher Order Component whether you’ve realized it or not.</p><p>A Higher Order Component (HOC for short) is React’s way over giving multiple components some repeated functionality or behavior, without having to reuse the same code over and over again in the component. Its a very clever way to follow the DRY (Dont Repeat Yourself) motto and cut down on code clutter.</p><p><strong>A HOC is a function that takes in a component as an argument and returns a new enhanced component.</strong></p><pre>const EnhancedComponent = higherOrderComponent(OriginalComponent)</pre><p>In the title image of this article I used the example of Bruce Wayne versus Batman. The main difference between the two is that Batman is an enhanced version of Bruce with a fancy suit and tons of gadgets he uses to fight crime. In this example Bruce is the original component, and Batman is the enhanced component. His suit (and gadgets and Batmobile) are the HOC.</p><pre>const Batman = withBatSuit(BruceWayne)</pre><p>The HOC withBatSuit will give Bruce access to his BatSuit object and turn him into Gotham’s own Dark Knight.</p><p>So how does it work exactly and when would it be appropriate to use one?</p><h4>When To Use a HOC</h4><p>Let’s say you have a project where you have multiple different counters counting some behavior. In one component, you have a button that counts the number of times it is clicked, then in other component you have a counter tracking the number of times you mouse over a certain div, then in yet another you are counting the number of times a certain page is visited. All of these components will have similar behavior (incrementing the count by 1 after some specific action) but since they are all slightly different we unfortunately can’t make then all the exact same component.</p><p>Now, before HOCs you would have to write the incrementCounter behavior into each one, and then have some sort of state variable that tracks the count. This is a lot of copy and pasting and repeating code though. What if we could give each component the incrementCounter function and also a state.count variable and then only tweak the action that trigger the incrementCounter function in each?</p><p>That’s exactly what we can do!</p><p>Another use case would be for something like determining how to display a page based on if a user is accessing it from his laptop, phone or tablet. If your website is mobile responsive, there is a pretty common pattern when you pass the component an object called isResponsive which is a boolean indicating true or false. Rather than passing this as props down to each component that needs access, you can render the component using a HOC called withResponsive that will give each component access to the isResponsive object dictating how it should be displayed to the user.</p><p>These are 2 common uses, but you can use it literally wherever you need multiple components to share some sort of behavior.</p><h3>Implementing a HOC in your App</h3><p>Let’s go back to our first example of adding a counter to multiple components in your app.</p><p>If we were to hard code the counter behavior into each app you’d end up with something like this:</p><h4><strong>App.js</strong></h4><pre>function App() {</pre><pre>return (<br>  &lt;div className=&quot;App&quot;&gt;<br>    &lt;ClickCounterWithoutHOC/&gt;<br>    &lt;HoverCounterWithoutHOC/&gt;<br>  &lt;/div&gt;<br>  );<br>}</pre><pre>export default App;</pre><h4><strong>ClickCounterWithoutHOC</strong></h4><pre>import React, {useState} from &#39;react&#39;</pre><pre>const ClickCounterWithoutHOC = () =&gt; {</pre><pre>  const [count, setCount] = useState(0)<br>  const incrementCount = () =&gt; setCount(prevCount =&gt; prevCount + 1)</pre><pre>  return (</pre><pre>  &lt;button onClick ={incrementCount}&gt;<br>    Clicked {count} times<br>  &lt;/button&gt;<br>  )<br>}</pre><pre><br>export default ClickCounterWithoutHOC</pre><h4>HoverCounterWithoutHOC</h4><pre>import React, {useState} from &#39;react&#39;</pre><pre>const HoverCounterWithoutHOC = () =&gt; {</pre><pre>  const [count, setCount] = useState(0)<br>  const incrementCount = () =&gt; setCount(prevCount =&gt; prevCount + 1)</pre><pre>return (</pre><pre>&lt;button onMouseOver ={incrementCount}&gt;<br>    Hovered {count} times<br>  &lt;/button&gt;<br>  )<br>}</pre><pre>export default HoverCounterWithoutHOC</pre><p>As you can see. This pattern is fine and it works, but we are repeating a lot of code between HoverCounter and ClickCounter. Now imagine a scenario where there are 5 or even 50 other components that need this counter behavior and all of a sudden you have a very inefficient codebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Sd33aO4hLNxNGTakhY4_QA.gif" /><figcaption>It works!</figcaption></figure><p>Instead let’s create a Higher Order Component called withCounter.js that will add this count and incrementCount behavior for us.</p><h4>withCounter</h4><pre>import React, {useState} from &#39;react&#39;</pre><pre>const withCounter = OriginalComponent =&gt; {<br>  const EnhancedComponent = () =&gt; {</pre><pre>   const [count, setCount] = useState(0)<br>   const incrementCount = () =&gt; setCount(prevCount =&gt; prevCount + 1)</pre><pre>    return (</pre><pre>      &lt;OriginalComponent<br>        incrementCount ={incrementCount}<br>        count={count}<br>      /&gt;<br>    )<br>  }<br>  return EnhancedComponent<br>}</pre><pre>export default withCounter</pre><p>You’ll see that what this component does is move the declarations of count and increment count into withCounter.js, and then it returns an EnhancedComponent which is just the OriginalComponent with incrementCount and count given to it as props.</p><p>Pretty simple concept once you see it in practice. Let me repeat that again.</p><p><strong>A Higher Order Component is just a function that takes in a component and enhances it by passing some behavior to it as props. The Higher Order Component then returns that new, enhanced component for you to use.</strong></p><p>Now let’s see how this affects ClickCounter and HoverCounter</p><h4>ClickCounter</h4><pre>import React from &#39;react&#39;<br>import withCounter from &#39;./withCounter&#39;</pre><pre>const ClickCounter = ({count, incrementCount}) =&gt; {</pre><pre>  return (<br>    &lt;button onClick ={incrementCount}&gt;<br>      Clicked {count} times<br>    &lt;/button&gt;<br>  )<br>}</pre><pre>export default withCounter(ClickCounter)</pre><h4>HoverCounter</h4><pre>import React from &#39;react&#39;<br>import withCounter from &#39;./withCounter&#39;</pre><pre>const HoverCounter = ({count, incrementCount}) =&gt; {</pre><pre>return (<br>    &lt;button onMouseOver ={incrementCount}&gt;<br>      Hovered {count} times<br>    &lt;/button&gt;<br>  )<br>}</pre><pre>export default withCounter(HoverCounter)</pre><p>Look how much cleaner this is compared to the counterparts about without the withCounter HOC.</p><p>All we need to do is import withCounter into each component, and at the bottom wrap our export with withCounter. This will export the enhanced version of our component.</p><p>Then, all we do is destructure our props, giving us access to count and incrementCount in the body of our JSX and we’re done!</p><p>Make sure you’re App.js file looks like this so you can test it out:</p><h4>App.js</h4><pre>function App() {</pre><pre>return (<br>  &lt;div className=&quot;App&quot;&gt;<br>    &lt;ClickCounter/&gt;<br>    &lt;HoverCounter/&gt;<br>  &lt;/div&gt;<br>  );<br>}</pre><pre>export default App;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Sd33aO4hLNxNGTakhY4_QA.gif" /><figcaption>Works exactly the same as before but much cleaner.</figcaption></figure><p>And there you have it! Here is the <a href="https://github.com/laflamablanc/Higher-Order-Components-Article/tree/main/src">link to my GitHub Repo</a> if you want access to any of the code from this article to play around with for yourself!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=204f0cd7bcfb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/what-is-a-higher-order-component-204f0cd7bcfb">What is a Higher Order Component?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Add Analytics to your React Application]]></title>
            <link>https://javascript.plainenglish.io/adding-analytics-to-your-react-application-b584265f9fae?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b584265f9fae</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 23:32:25 GMT</pubDate>
            <atom:updated>2021-06-23T03:21:17.240Z</atom:updated>
            <content:encoded><![CDATA[<p>Using Amplitude’s npm library</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIpXYT-xmKpeXK8hvxgWHQ.png" /></figure><h3>Amplitude</h3><p>Amplitude is a data analytics startup that aims to make adding analytics to your web or mobile app simple and easy. It is a Y Combinator company and has backing from some major VC firms such as Sequoia.</p><p>Due to its effectiveness and simplicity, they have seen a massive boom in customer growth during the pandemic, and a massive rise in valuation to go with it (recently valued at $4B as of writing this article).</p><p>All of these reasons (the simplicity, the customization options, the clean UI, the strong adoption in the industry) are the reason my company chose to use them to handle our data analytics on our React app. Here is how you can add it to yours:</p><h3>Signup</h3><p>The first step will be to signup for a trial at <a href="https://amplitude.com/">Amplitude’s website</a>. You will need to create an account and give some basic information about your company/app.</p><p>Once you create an account, you will be brought to the dashboard where all of your data will live. It will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xq8FSN9JXUs6A2Wf775tIg.png" /><figcaption>Source: <a href="https://analytics.amplitude.com/login/my-demo">https://analytics.amplitude.com/login/my-demo</a></figcaption></figure><p>Here you will have access to some extremely important info such as the number of daily, weekly, and monthly active users, and how those trends have evolved over time.</p><p>You can also see info such as user retention rate, time spent on the app, conversion rate for various marketing campaigns, and the results of A/B testing on your site or for things like a landing page. You can even fine-tune results, for example, if you wanted to see the number of users that come to your app from Twitter and who click at least 2 pages on your app, you can see that using the Amplitude dashboard!</p><h3>Integrating with React</h3><p>The easiest way to add the Amplitude tracking to your app is via their <a href="https://www.npmjs.com/package/amplitude-js">npm package</a>. Simply run:</p><pre>npm i amplitude-js</pre><p>Then inside your React app create a file called ‘amplitude.js’</p><p>Inside add the following:</p><pre>import amplitude from &quot;amplitude-js&quot;;</pre><pre>//Code to import config info about your app</pre><pre>import { env } from &quot;services/configs&quot;;</pre><pre>const API_KEY =</pre><pre>env === &quot;app&quot;</pre><pre>? &quot;PRODUCTION_API_KEY_HERE&quot;</pre><pre>: &quot;DEV_API_KEY_HERE&quot;;</pre><pre>//If you only have one environment, just put the single API key</pre><pre>amplitude.getInstance().init(API_KEY, null, {</pre><pre>// optional configuration options</pre><pre>  includeUtm: true,</pre><pre>  includeGclid: true,</pre><pre>  includeReferrer: true,</pre><pre>});</pre><pre>export { amplitude };</pre><p>So let’s unpack this code.</p><p>At the top, I’m importing something called env from my configs folder. This is the config file for my app and contains a bunch of information about how I’m loading it up. It contains some info for API keys and my database, but it also contains this line of code:</p><pre>export const env = process.env.REACT_APP_ENV;</pre><p>If set up correctly, this will give information about what environment your React app is currently using. In my case, it only has 2 possibilities “dev” (for the development, non-live environment) or “app” (for the real live deployed app).</p><p>Next, you’ll need your API Key. Based on the environment you’re working in, you may have different Amplitude projects set up, each with its own key. You can find the key on your project’s <a href="https://help.amplitude.com/hc/en-us/articles/360043750992">Setting page</a>. Make sure to replace the string above with your project’s correct key.</p><p>Finally, you have an options object that you can pass the init function in order to load Amplitude with certain features.</p><p>Here is a list of <a href="https://github.com/amplitude/Amplitude-JavaScript/blob/main/src/options.js">all possible options and their descriptions</a>. In my case, I’m initializing with the includeUtm, includeGclid, and includeReferrer options.</p><p>Finally, you just want to export this initialized amplitude object at the bottom of your file. This will be what you import into your app to add the event tracking.</p><h4>Adding tracking to components</h4><p>Now, wherever you want to use Amplitude tracking, you’ll want to make sure you import your newly created Amplitude object at the top of the code (make sure to put the correct filepath if it doesn’t match mine).</p><pre><strong>import { amplitude } from &quot;components/amplitude&quot;;</strong></pre><pre>import logo from &#39;./logo.svg&#39;;</pre><pre>import &#39;./App.css&#39;;</pre><pre>function App() {</pre><pre>return (<br>  &lt;div className=&quot;App&quot;&gt;<br>    &lt;div&gt; My App &lt;/div&gt;<br>  &lt;/div&gt;<br>  );<br>}</pre><pre>export default App;</pre><p>Let’s say you want to track the number of times that a cart button is clicked in your e-commerce app.</p><pre><strong>import { amplitude } from &quot;components/amplitude&quot;;</strong></pre><pre>import logo from &#39;./logo.svg&#39;;<br>import ItemCard from &#39;components/ItemCard&#39;;</pre><pre>import &#39;./App.css&#39;;</pre><pre>function App() {</pre><pre>displayItems = () =&gt; {<br>  props.items.map(item =&gt; &lt;ItemCard name=item.name/&gt;<br>}</pre><pre><strong>logClick = () =&gt; {<br>  </strong><strong>amplitude.getInstance().logEvent(&#39;cartButtonClicked&#39;, itemsInCart)<br>}</strong></pre><pre>return (<br>  &lt;div className=&quot;App&quot;&gt;<br>    &lt;h1&gt;My E-Commerce Store&lt;/h1&gt;<br>      {displayItems}<br>      &lt;Button onClick={<strong>logClick</strong>}&gt; Add to Cart &lt;/Button&gt;</pre><pre>  &lt;/div&gt;<br>  );<br>}</pre><pre>export default App;</pre><p>You can then add something like this to your code where each time the button is clicked, it logs the event with a ‘cartButtonClicked’ type and then keeps track of all the items in that users cart.</p><p>Get creative with it, and you can being to track all kinds of things.</p><p>A lot of people use it for error tracking as well.</p><p>Let’s say you want to track user signups from a certain ad campaign. You can add something this to your code where Status 3 means the user completed signup:</p><pre>&lt;Route</pre><pre>{...rest}<br>  render={(routeProps) =&gt; {<br>    if (RedirectComponent &amp;&amp; status !== 3) {<br>      return &lt;RedirectComponent {...props} {...routeProps} /&gt;;<br>    } else if (status === 0) {<br>      return &lt;NotLoggedIn /&gt;;<br>    } else if (status === 1 || status === 2) {<br>      return &lt;Redirect to=&quot;/onboarding&quot; /&gt;;<br>    } else if (status === 3) {<br>      analyticsMessage &amp;&amp; analytics.logEvent(analyticsMessage);<br>      analyticsMessage &amp;&amp;<br>        <strong>amplitude.getInstance().logEvent(analyticsMessage)</strong>;<br>    return &lt;Component {...props} {...routeProps} /&gt;;<br>    }<br>  }}<br>/&gt;</pre><p>Now if the user is status 3, the event gets logged to Amplitude so you can track the conversion rate.</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=b584265f9fae" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/adding-analytics-to-your-react-application-b584265f9fae">How to Add Analytics to your React Application</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[Redux with React’s Functional Components]]></title>
            <link>https://medium.com/geekculture/redux-with-reacts-functional-components-272f1008ee69?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/272f1008ee69</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Fri, 04 Jun 2021 02:41:15 GMT</pubDate>
            <atom:updated>2021-06-10T07:01:54.121Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to use Redux’s useSelector and useDispatch hooks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IPzq9sMr8Vq4ALjI83dBfw.png" /></figure><p>Before reading this you should familiarize yourself with what Redux is and <a href="https://medium.com/@bretcameron/a-beginners-guide-to-redux-with-react-50309ae09a14">how to use it in React class components</a>.</p><h3>Setup</h3><p>Start by creating a new react app. I’ll be using a package called Redux Toolkit to get the shell of the app set up quickly. If you’d like to do the same run:</p><pre>npx create-react-app my-app --template redux</pre><p>This creates your React app to use the official template for working with Redux. Then inside your app run:</p><pre>npm install @reduxjs/toolkit react-redux<br>npm install redux</pre><p>At src/app/store.js create the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9bbf085e6b66c88d37e24997c5a0c2/href">https://medium.com/media/bf9bbf085e6b66c88d37e24997c5a0c2/href</a></iframe><p>Then, head to index.js and wrap your App component like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfdd10746641ce98549f802477ba9a0d/href">https://medium.com/media/cfdd10746641ce98549f802477ba9a0d/href</a></iframe><p>Now you are all setup.</p><h4>Counter Component</h4><p>For this example, we will be creating a simple counter.</p><p>When using a Class component, you would see something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/080d171d19231fc3cc25af377abf6a26/href">https://medium.com/media/080d171d19231fc3cc25af377abf6a26/href</a></iframe><p>This is the standard Redux setup, where we use mapStateToProps to get access to properties on the Redux store available to our component as props, and then dispatch actions to our reducer (also available as props) in order to update those properties.</p><p>When using Hooks however we need to do things a little differently.</p><h3>useSelector</h3><p>The useSelector hook is how we are going to mimic the mapStateToProps function in our component.</p><p>Start by importing useSelector from ‘react-redux’.</p><pre>import { useSelector} from &#39;react-redux&#39;</pre><p>Very similar to the useState hook, you will declare a variable at the top of your component and set it equal to the return value of the useSelector function. The useSelector function takes another function as its parameter. This function will be passed the entire state object as its parameter.</p><pre>const count = useSelector((state) =&gt; state.counter)</pre><p>So basically, you’re writing a function that has state as its argument and then returns some property off of that state object (in this case the value of the counter). Then, you pass that function to useSelector which is what gives the function access to the state object. Then, you are assigning the return value of your function inside of your function to the variable you declared (in this case count).</p><p>Confusing enough for you?</p><p>Essentially this:</p><pre>const mapStateToProps = (state, props) = {</pre><pre>  counter: state.counter,</pre><pre>  user: state.user</pre><pre>}</pre><p>And this:</p><pre>const count = useSelector((state) =&gt; state.counter)</pre><pre>const user = useSelector((state) =&gt; state.user)</pre><p>Are doing the exact same thing with slightly different syntax.</p><h3>useDispatch</h3><p>In my opinion, useDispatch is actually much simpler. It reminds me a lot of useHistory.</p><p>First, we need to import it:</p><pre>import { useSelector, <strong>useHistory</strong>} from &#39;react-redux&#39;</pre><p>Then, all you need to do is put this at the top of your component:</p><pre>const dispatch = useDispatch()</pre><p>Now, you have a function called dispatch that will send whatever you pass it to the reducer. It’s actually a lot more simple to use than mapDispatchToProps. Just like before we want to import our actions from redux/actions</p><pre>import { incrementCounter, decrementCounter } from &#39;../redux/actions/counterActions.js&#39;</pre><p>But instead of doing the whole complicated process of adding these functions to another function, and then mapping that outer function to our props, we can just do this:</p><pre>onClick={() =&gt; dispatch(decrementCounter())}</pre><p>No props necessary, and we define the function right in our JSX in one line of code!</p><p>The final component will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/080d171d19231fc3cc25af377abf6a26/href">https://medium.com/media/080d171d19231fc3cc25af377abf6a26/href</a></iframe><p>Notice that we no longer need the connect function at the bottom of our component export to get Redux to work properly.</p><p>And there’s a quick intro to using Redux with Hooks!</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=272f1008ee69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/redux-with-reacts-functional-components-272f1008ee69">Redux with React’s Functional Components</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Redux and Firestore in Your React Web App]]></title>
            <link>https://javascript.plainenglish.io/using-redux-and-firestore-in-your-react-web-app-eb38a9b316f8?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb38a9b316f8</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Thu, 27 May 2021 01:23:03 GMT</pubDate>
            <atom:updated>2021-05-27T14:05:54.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UlxxmP6ESTWYGzHFg7wDDQ.png" /><figcaption>Redux is a state management framework and Firestore is a NoSQL database provided by Google</figcaption></figure><h3>Redux</h3><h4>Intro</h4><p>Redux is a state management tool for JavaScript, that makes it much simpler to maintain state in your application.</p><p>It is especially useful in React applications because it lets you avoid the behavior of passing props down through many different child components until it reaches a deeply nested component that needs the data.</p><p>Instead, all of the state information for your app is stored in something appropriately called a <em>store. </em><a href="https://redux.js.org/faq/store-setup">Here is a guide</a> on how to set up the store in your React app</p><p>With Redux, once a store is created, any component that is set up to use Redux’s functionality can access information directly from the store. You no longer need to worry about passing down props or using callbacks to update parents. Redux’s MapStateToProps and MapDispatchToProps functions (combined with something called a reducer) will handle all of this for you.</p><h4>mapStateToProps</h4><p>The mapStateToProps function does exactly what its name says. It will map whichever items in the store that you want your component to have access to, to your components props. This may sound confusing but it’s not too bad when you see an example.</p><p>Let’s say we have a component called Groceries. We want to give our Groceries component access to the current list of all the groceries stored in our app’s state. These exist on an attribute called state.groceryList.</p><pre>// Groceries.js</pre><pre>function mapStateToProps(state) {</pre><pre>  const { groceryList } = state</pre><pre>  return { <br>    fruits: groceryList.fruits<br>    veggies: groceryList.veggies<br>    dairy: groceryList.dairy<br>  }</pre><pre>}</pre><pre>export default connect(mapStateToProps)(Groceries)</pre><p>Line by line, the mapStateToProps function is passed an argument ‘state’ which represents the entire Redux store.</p><p>Then, prop destructuring is used to pull the property groceryList off of state, and assign it to a variable also called groceryList.</p><p>From there, the return value of mapStateToProps represents the attributes that will be added to your components prop object. Therefore, in the example above, Groceries will have props.fruits, props.veggies, and props.dairy all added to whatever other props are being passed down into Groceries by its parent.</p><p>The final line is what is giving Groceries this ability to give itself props. The connect function takes in 1 or 2 functions (in this case the 2nd argument of mapDispatchToProps is blank) and then assigns the return value of each function to the props object of Groceries. You could theoretically call this function whatever you want, and connect will still assign the return value of its first argument to your props, but the convention is to call it mapStateToProps.</p><h4>mapDispatchToProps</h4><p>The mapDispatchToProps function does a very similar thing to mapStateToProps, but instead of giving you access to the app&#39;s state, it gives your component functions called actions that are used to update Redux’s state.</p><p>They do accomplish this by dispatching an action to a file called a reducer. I will explain the reducer in the next section, so for now, let’s focus on the mapDispatchToProps function.</p><p>Let’s say we are storing a user’s name in our app’s state using redux. The first time the app loads up, it may not yet know your name, or there may be some other functionality where you need to change the user’s name. In order to set/update this name property, we need to use a Redux action that updates the store. This is where mapDispatchToProps comes in.</p><p>We’ll start with the code to actually perform the name update.</p><pre>const setName = (name) =&gt; ({<br>  type: &#39;SET_NAME&#39;,<br>  name,<br>})</pre><p>So what you want to do is pass setName a string representing whatever the name should be. Then, at the bottom of your component you want to create the mapDispatchToProps function like so:</p><pre>const mapDispatchToProps = (dispatch) =&gt; ({<br>  setName: (name) =&gt; dispatch(setName(name)),<br>})</pre><p>The above function takes in the dispatch function as an argument. This function then returns an object with a setName property, the value of which is also a function. The setName property is a function which takes in an argument of name, it then passes the setName function which we defined in the first code block as a parameter of the dispatch function. This will all be mapped to the component&#39;s props, so you will have access to this function by calling props.setName.</p><p>Then, dispatch sends the return of the setName(name) function to the rootReducer. Remember the return value of setName(name) is an object with a type property of ‘SET_NAME’ and a name property of the name string you pass it.</p><h4>Reducers</h4><p>The reducer is made up of a bunch of switch-case statements. If the type attribute of the action it is passed matches one of the cases, you will hit the corresponding code inside of the case statement. Again, this is hard to explain in words so let’s see an example:</p><pre>const name = (state = &#39;&#39;, action) =&gt; {<br>  switch(action.type) {<br>    case &#39;SET_NAME&#39;:<br>      return action.name;<br>    default :<br>       return state;<br>  }<br>}</pre><p>Continuing with the setName example, our reducer is passed the setName action, which has a type of ‘SET_NAME’. since action.type matches the case of ‘SET_NAME’ in our reducer, our reducer will return action.name which is the string containing the name we want to save in the Redux store.</p><p>Now, if you look at Redux’s state.name property it will be whatever the name passed to it by setName was. So putting it all together:</p><pre>//calling:</pre><pre>props.setName(&#39;Chris&#39;)</pre><pre>//results in dispatch calling:</pre><pre>dispatch(setName(&#39;Chris&#39;))</pre><pre>//which then is passed to our reducer as:</pre><pre>const name = (&#39;&#39;, {type: &#39;SET_NAME&#39;, name: &#39;Chris&#39;})</pre><pre>//when ends up setting store.state.name = &#39;Chris&#39;</pre><h4>Connect</h4><p>The final step in getting all of these actions, state variables, and reducer to work together is the handy connect function. Connect is a function provided by Redux (remember to import it from ‘react-redux’ at the top of your component) that wraps your component and allows it to pass itself props effectively.</p><p>Connect takes up to 4 optional arguments, but they have to be in a defined order. Today we will just focus on the first 2 which are mapStateToProps and mapDispatchToProps.</p><pre>import { connect } from &#39;react-redux&#39;</pre><pre>const connectToStore = connect(mapStateToProps, mapDispatchToProps)<br>const ConnectedComponent = connectToStore(Component)</pre><p>The above function will map the return values of mSP and mDP to to the props of your component. connect returns another function that accepts the component is should wrap as an argument.</p><p>You will actually usually see it done in one step like so:</p><pre>connect(mapStateToProps, mapDispatchToProps)(Component)</pre><p>This is the exact same thing as the 2 lines above, but much cleaner and is generally the expected syntax so make sure to learn it this way.</p><p>You don’t always want both mapStateToProps and mapDispatch to props in your component, so neither is necessary. If you only want mapStateToProps you can only pass one argument like so:</p><pre>connect(mapStateToProps)(Component)</pre><p>However, if you only want mapDispatchToProps, since connect is expecting mapStateToProps as the 1st argument, you need to pass null in the first slot like so:</p><pre>connect(null, mapDispatchToProps)(Component)</pre><h3>Firestore</h3><p>There is a very useful package you can install to use Redux with Firebase in your React app called appropriately <a href="http://react-redux-firebase.com/docs/getting_started">react-redux-firebase</a>.</p><h4>firestoreConnect</h4><p>The react-redux-firebase npm provides a Higher Order Function called firestoreConnect that allows you to listen/unlisten for updates to the Firestore using React’s lifecycle hooks.</p><p>Let’s say you had a database of chats and messages in Firestore and you wanted to listen for any changes so you can re-render your app. You can use firestoreConnect and pass it an array containing the paths you want listened to. It would look something like this:</p><pre>firestoreConnect(() =&gt; [&#39;todos&#39;]), // sync todos collection from Firestore into redux</pre><p>A more complex version may even look something like this:</p><pre>firestoreConnect((props) =&gt; [</pre><pre>  {<br>    collection: &quot;chats&quot;,<br>    doc: props.match.params.chatId,<br>    subcollections: [<br>      {<br>      collection: &quot;messages&quot;,<br>      orderBy: [&quot;timestamp&quot;, &quot;desc&quot;],<br>      },<br>    ],</pre><pre>    limit: props.convLimit</pre><pre>    storeAs: &quot;conversation_&quot; + props.match.params.chatId,</pre><pre>   },<br>])</pre><p>You will now have access to all of these collections and documents from Firestore directly in Redux.</p><h3>Bringing It all Together</h3><p>Finally, to get all of these different pieces to work together, we will use a function provided by the Redux library called compose.</p><h4>Compose</h4><p>What compose allows you to do is string multiple “store enhancers” together in a clean syntax without having to pass them to each other as arguments. When using connect with firestoreConnect the following syntax is what you want:</p><pre>export default compose(</pre><pre>  connect(mapStateToProps, mapDispatchToProps),<br>  firestoreConnect(() =&gt; [&#39;todos&#39;])</pre><pre>)(Component);</pre><p>You’ve now connected all of the functionality of mapStateToProps, mapDispatchToProps, and fireStoreConnect to your component!</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=eb38a9b316f8" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/using-redux-and-firestore-in-your-react-web-app-eb38a9b316f8">Using Redux and Firestore in Your React Web App</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[Best Practices for Passing Props in React]]></title>
            <link>https://javascript.plainenglish.io/best-practices-passing-props-in-react-9f6706bc05a?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f6706bc05a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Fri, 21 May 2021 18:00:04 GMT</pubDate>
            <atom:updated>2021-06-23T04:47:53.769Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*J1hOlYReJiKG0lxH1E4JeQ.png" /><figcaption>Source: <a href="https://vuejs.org/">https://vuejs.org/</a></figcaption></figure><h3>Introduction</h3><p>One of the nicest things about React’s component style of coding is the clear relationships defined between Parent and Child elements. Very often you will run into a scenario where a Parent component is responsible for rendering a Child component with different characteristics or display properties depending on some action by the user. In this case, you would pass the Child component different “props” which are then used inside of it to display data in some way.</p><p>This is useful because it lets you consider each component in complete isolation. This is referred to as “separation of concerns”. The component will either define or have passed into it all of the information necessary to render data to the screen.</p><h3>Props</h3><p>Props is short for properties, and they are arguments passed into a Child Component usually by the Parent (if using Redux this is not always the case).</p><p>The proper way to pass props into the Child component is like so:</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Welcome name=&quot;Sara&quot; /&gt;<br>      &lt;Welcome name=&quot;Cahal&quot; /&gt;<br>      &lt;Welcome name=&quot;Edite&quot; /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>In this example, App is the Parent and Welcome is the Child. The property “name” is passed into each of the Welcome components.</p><p>Now inside Welcome you will have access to the name prop via the prop object that is passed into every component. This prop object is always there whether props are passed in or not.</p><h4>Props in Class Components</h4><pre>class Welcome extends React.Component {<br>  render() {<br>    return &lt;h1&gt;Hello, {<strong>this.props.name</strong>}&lt;/h1&gt;;<br>  }<br>}</pre><p>In class components, you access props using the syntax ‘this.props’.</p><p>In the example above Welcome was passed the name prop, so you can display this information programmatically by accessing the name property on this.props. And putting it inside curly braces.</p><h4>Props in Functional Components</h4><pre>function Welcome(<strong>props</strong>) {<br>  return &lt;h1&gt;Hello, {<strong>props.name</strong>}&lt;/h1&gt;;<br>}</pre><p>In functional components, the logic is very similar with a slight change in syntax. You need to pass in an argument called props into the function definition of your component, and then you can access the properties on it without using this selector. You can just call ‘props.propertyname’ directly.</p><h4>Passing Props Dynamically</h4><p>Going back to our example of passing from App to Welcome, the first way we did it by manually typing out Welcome and name each time isn’t very clean code for when you could have a large app with 100+ Welcome names. Instead, you want to map over an array of all names and pass a variable representing the name into each Welcome component as a prop. This is done like so:</p><pre>names = [&#39;Sara&#39;, &#39;Cahal&#39;, &#39;Edite&#39;]</pre><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      names.map(name =&gt; &lt;Welcome name ={name}/&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>This is much cleaner code, and you can pass a dynamic name prop into the Welcome component by wrapping it in curly braces.</p><h3>Destructuring Props</h3><p>Let’s say you have a large API of users with more than just a name attribute attached. Each user has a name, username, age, gender, and date of birth associated with them. Rather than passing each of these props individually like so:</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Welcome<br>        name=&quot;Sara&quot;<br>        username =&quot;sara12&quot;<br>        age=23<br>        gender=female<br>        dob=&quot;7/12/1997&quot;<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>You can instead pass the props as an object and destructure them using the new syntax provided by ES6.</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Welcome userObj = {userObj} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>There are 2 ways to do this.</p><h4>Destructuring Inside Component</h4><p>This is usually done in class components, but can be done in functional components also if you prefer.</p><pre>class Welcome extends React.Component {<br>  <strong>{name, username, age, gender, dob}= this.props</strong></pre><pre>  render() {<br>    return (<br>      &lt;h1&gt;Hello, {name}&lt;/h1&gt;;<br>      &lt;div&gt;<br>        Age: {age}<br>        Gender: {gender}<br>        Date of Birth: {dob}<br>      &lt;/div&gt;<br>  }<br>}</pre><p>What this code does is effective say for each of the variables in curly braces, look for an attribute on this.props with a corresponding name and assign its value to the variable. It’s the same as doing this but much cleaner:</p><pre>class Welcome extends React.Component {<br><strong>  let name = this.props.name<br>  let username = this.props.username<br>  let age = this.props.age<br>  let gender = this.props.gender<br>  let dob = this.props.dob</strong></pre><pre>  render() {<br>    return (<br>      &lt;h1&gt;Hello, {name}&lt;/h1&gt;;<br>      &lt;div&gt;<br>        Age: {age}<br>        Gender: {gender}<br>        Date of Birth: {dob}<br>      &lt;/div&gt;<br>  }<br>}</pre><h4>Destructuring Inside Component Function Definition</h4><p>This is the way you’ll often see it done in functional components. You can actually destructure it directly where you would normally pass in the props argument by passing an object containing the variable names.</p><pre>function Welcome(<strong>{name, username, age, gender, dob}</strong>) {</pre><pre>render() {<br>    return (<br>      &lt;h1&gt;Hello, {name}&lt;/h1&gt;;<br>      &lt;div&gt;<br>        Age: {age}<br>        Gender: {gender}<br>        Date of Birth: {dob}<br>      &lt;/div&gt;<br>  }<br>}</pre><p>Now you can access these variables directly in the JSX code and you don’t even need the extra line of code destructuring the object. You can do it right in the function definition!</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=9f6706bc05a" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/best-practices-passing-props-in-react-9f6706bc05a">Best Practices for Passing Props 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[Git Stash and Git Rebase]]></title>
            <link>https://levelup.gitconnected.com/git-stash-and-git-rebase-535811a3cb84?source=rss-175b874719d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/535811a3cb84</guid>
            <category><![CDATA[git-stash]]></category>
            <category><![CDATA[git-rebase]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Sean LaFlam]]></dc:creator>
            <pubDate>Sun, 16 May 2021 21:43:06 GMT</pubDate>
            <atom:updated>2021-05-22T22:52:02.010Z</atom:updated>
            <content:encoded><![CDATA[<h4>When to use them and how to handle merging your code to master</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*BCZkmZR1_YzDZy22Vn4uUw.png" /></figure><p>When I was first learning to code, I would be the only engineer working on an app. Every once in a while I would have a project I would be working on with one other engineer, but a lot of the progress was made during pair programming sessions, where we would just push all the changes directly to master.</p><p>When I moved onto larger apps and began working at a company with a dozen engineers I began learning how to use branches, and how to use pull requests to merge my changes to the code base without affecting the other engineers code. Two of the most useful commands I have found are ‘git rebase’ and ‘git stash’. In conjunction with other commands such as git pull, git merge, etc. you start to realize truly how powerful of a tool git is.</p><h4>Git Stash</h4><p>As you start working on larger team, and especially one who’s product is currently live, there are times where you may begin working on a branch but will have to suddenly switch off of it to address some more urgent issues.</p><p>If you were to simply use git checkout to switch to the branch git will attempt to bring all of your changes on your current branch (Branch A) over to the branch you’re switching to (Branch B). Sometimes it will switch with no issue if there are no conflicts, but other times it will give you a warning that you need to commit your changes before checking out the new branch.</p><p>Either way, many times you do not want to bring the new code that you’ve been working on Branch A over to Branch B. What you want to do is save the code you’ve added, but when you switch to Branch B you would like it to revert back to the state it was in before you created Branch A. This is exactly what git stash was designed to do.</p><p>The git stash command helps you <em>stash</em> your work away and clear your working directory. Then when you checkout it will not carry over the new code with you.</p><p>Now let’s say you went and fixed the urgent error in Branch B, and you decided you want to import these changes that you made on Branch A. You can use the command git stash list to see a list of all the changes you’ve stored in the <em>stash</em>. From there you can apply these changes using the command git stash apply &lt;stash_name&gt; where stash_name is the name given by the list command (will looks something like stash@{0}: )</p><p>Finally, you can use the command git stash drop &lt;stash_name&gt; to remove an old or unwanted stash from your list.</p><h4>Git Rebase</h4><p>The command git rebase applies your commits on top of another branch. Here is an effective diagram I found online to explain it.</p><p>Let’s say you branch off of master and start adding a new feature to your app. While you’re working, a part of your app’s code that your new feature relies on what changed to fix a bug. Your code now is different from master in both your new feature, and some other bug fixes, so you are several commits both behind master and ahead of master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NUrB9WYTAQGLalEgpBrWQ.png" /><figcaption>Blue is the commits to fix a bug, and green represent your new feature commits.</figcaption></figure><p>When you go to merge your code there are a bunch of merge conflicts that you aren’t sure how to resolve. If only there was a way to pull the bug fixes on master into your branch, and THEN add the commits for your new feature onto the fixed up code.</p><p>You’re in luck, this is exactly what git rebase does! It will move your new feature to the tail end of the new commits on master, creating one continuous flow of commits that should be conflict free, and replaces the need to merge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OuHM7kCHrJw-NFwnNYITw.png" /></figure><p>These 2 commands should really enhance your ability to avoid conflicts and move around from branch to branch on a larger team!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=535811a3cb84" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/git-stash-and-git-rebase-535811a3cb84">Git Stash and Git Rebase</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>