<?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 Alex on Medium]]></title>
        <description><![CDATA[Stories by Alex on Medium]]></description>
        <link>https://medium.com/@alex_holachek?source=rss-d09f5ddb8967------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nMAkpjckuq8kfDwM.jpg</url>
            <title>Stories by Alex on Medium</title>
            <link>https://medium.com/@alex_holachek?source=rss-d09f5ddb8967------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 20:44:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alex_holachek/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[Storybook Mobile]]></title>
            <link>https://medium.com/storybookjs/storybook-mobile-6c654d44fc64?source=rss-d09f5ddb8967------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c654d44fc64</guid>
            <category><![CDATA[mobile-web]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[features]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alex]]></dc:creator>
            <pubDate>Tue, 08 Dec 2020 15:54:50 GMT</pubDate>
            <atom:updated>2020-12-08T15:54:50.416Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Build mobile-ready UIs faster with contextual hints</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*Veht03z3QlgzuxHSgyoqyA.gif" /><figcaption>Storybook Mobile in action</figcaption></figure><p>Almost every frontend developer has been guilty of this at least once: you quickly build some bit of UI that works fine in Chrome on a powerful laptop with a good internet connection, and then you go ahead and ship it.</p><p>Now, your users have to contend with a brittle UI. It might be broken for people who use their keyboard to navigate, or it could look janky on a slow connection. Maybe it renders really poorly in mobile Safari.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*sSrZvXI1DTWIG9IAWY9ikA.png" /><figcaption>One component can be rendered on many devices and browsers</figcaption></figure><p>It’s a lot of work to build solid UI components that perform well in all circumstances, and one area that’s particularly easy for desktop-based developers to overlook is mobile devices. Even if you adhere to all the best practices of responsive design and make sure that your UI looks good on smaller devices, you could still be shipping a product that is missing all the details that make an experience usable, smooth and performant on a touchscreen device.</p><p>Mobile-web browsers account for about 50% of website visits, yet many mobile web best practices are frequently overlooked. I became increasingly aware of this issue after noticing how differently various popular websites performed on my phone — they ran the gamut from totally smooth and intuitive UIs, to near unusable ones. After spending time collecting UX best practices for mobile, I decided that it would be helpful to create an interactive tool to proactively guide developers towards using mobile web best practices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*l6Xze_Rr0TUh0tIh8Yn-dg.png" /></figure><h3>Storybook to the rescue</h3><p>Having the right tools sets developers up for success, and I like <a href="http://storybook.js.org/">Storybook</a> because it gives me the mental space to think in isolated components and experiment with component states as I work. Storybook has <a href="https://storybook.js.org/addons">a variety of helpful addons</a> that make it easier to pick up on usability issues during the development process. For example, the Storybook <a href="https://www.npmjs.com/package/@storybook/addon-a11y">accessibility addon</a> scans the rendered HTML of your stories for possible accessibility issues.</p><p>Inspired by the accessibility addon, I built an addon that integrates the mobile hints and facts I compiled over the years directly into my daily workflow. <a href="https://github.com/aholachek/storybook-mobile"><strong>Storybook Mobile</strong></a> provides hints and suggestions in context, depending on the content of each individual component as it has been rendered into the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*VFxuN8oG-h6sJUQvWeJHwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*MAaRwI3KGzPxhQunZG6ZEQ.png" /><figcaption>Example warning messages and hints that appear alongside your component</figcaption></figure><h3>How to create better UI components for the mobile web</h3><p>If you’d like to see the addon in action, you can <a href="https://storybook-mobile.netlify.app/?path=/story/signup-form--default">check out a working demo here.</a> The Storybook Mobile addon scans your component to detect issues like too-small touch target sizes, missing :active CSS styles, and non-responsive images, and warns you about them in the addon panel.</p><p>Storybook Mobile also provides contextual hints for mobile web forms. Let’s take a quick look at some of the things it can surface regarding forms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oQtWWBR-8SwnISax" /><figcaption><em>Example of the hints Storybook Mobile offers for forms</em></figcaption></figure><p>If you’ve ever filled in forms on your phone, you probably know how frustrating it can be. There are several simple ways to make sure that web forms work well on mobile devices, but they’re easy for developers to forget.</p><p>Take for example the case of a form input meant to take a zip code. An MVP version (ignoring the label) might look something like this:</p><pre>&lt;input type=&quot;text&quot; /&gt;</pre><p>But we can do better. First, we should ensure that input fields are tagged with the correct autocomplete values. That allows devices to pre-fill fields with the proper information, which saves users time. Next, we can use appropriate HTML5 input type (and possibly inputmode) into ensure that when a user taps an input field, their device shows the appropriate style of keyboard.</p><p>Taking the above into account, a more thoughtful input tailored for zip code entry might look something closer to this:</p><pre>&lt;input type=&quot;text&quot; inputmode=&quot;decimal&quot; autocomplete=&quot;postal-code&quot;/&gt;</pre><p>Even if you know all about these params, it’s fairly easy to forget to optimize form input typeand autocomplete params every single time you build a form. The contextual hints offered by Storybook Mobile attempt to make it easier to get it right every time.</p><p>If this is the first time you’re hearing about mobile-optimized forms, or if you’d like to review, <a href="https://better-mobile-inputs.netlify.app/">try experimenting with this tool I made to help you view different input configurations on a simulated mobile device.</a></p><h3>How Storybook Mobile works under the hood</h3><p>Storybook Mobile loads in a panel beside the currently displayed UI component. Every time you focus on a new story, Storybook Mobile gets sent a new payload of your story’s rendered HTML. It inspects the markup and the rendered component using various DOM APIs.</p><p>This workflow can be used to create other addons that surface different contextual hints and suggestions, beyond the scope of Storybook Mobile. If that sounds intriguing, you can learn more about <a href="https://www.chromatic.com/blog/how-to-build-a-storybook-addon/">creating Storybook addons here</a>.</p><h3>Install Storybook Mobile</h3><p>First install the addon from npm:</p><pre>yarn add -D storybook-mobile </pre><p>or</p><pre>npm install --save-dev storybook-mobile</pre><p>Next, add storybook-mobile to your list of addons:</p><pre>// .storybook/main.js</pre><pre>module.exports = {</pre><pre>  addons: [</pre><pre>+    &#39;storybook-mobile&#39;</pre><pre>  ]</pre><pre>}</pre><p>And if you want to dive into the code, <a href="https://github.com/aholachek/storybook-mobile">check out the repo for Storybook Mobile here.</a> Feel free to open an issue if you have any questions or suggestions!</p><h4>Get involved</h4><p>To get the latest addons and Storybook news sign up to the Storybook mailing list. Check out Storybook on <a href="https://github.com/storybooks/storybook">GitHub</a> and join the <a href="https://discord.gg/AaVxNMD">Discord</a> chat.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fd42fc0%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fd42fc0%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/9875acdd1d756e7af50bf68488b92f2d/href">https://medium.com/media/9875acdd1d756e7af50bf68488b92f2d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c654d44fc64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/storybookjs/storybook-mobile-6c654d44fc64">Storybook Mobile</a> was originally published in <a href="https://medium.com/storybookjs">Storybook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep your Large Redux Application In Check with Redux-Usage-Report]]></title>
            <link>https://medium.com/about-codecademy/keep-your-large-redux-application-in-check-with-redux-usage-report-e2e4f31bb86f?source=rss-d09f5ddb8967------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2e4f31bb86f</guid>
            <category><![CDATA[devtools]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alex]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 18:11:15 GMT</pubDate>
            <atom:updated>2018-02-06T14:29:23.649Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*_ynPGSWJ3dcoR9zF3vh4kg.png" /></figure><p>One of the refreshing things about moving to Redux from other types of state management is how easy it becomes to understand what’s going on in your app. You can use Redux Devtools to get a complete picture of the current state, and trace the series of actions that got it there. It’s all in one place, in a single object tree. Everything seems so much more transparent than before.</p><p>As your app grows, however, and multiple developers work on features that add more and more data to the store, things can start to get foggy again. Maybe some data is being passed down from the server, but no longer actually used, bloating the store. Or maybe the entities aren’t fully normalized, leading to confusing duplication. Sometimes, it’s simply difficult to discern which components are accessing which parts of the store, or to get a clear sense of how data is flowing through the app.</p><p>Codecademy was an early adopter of Redux and, as our app has matured, we’ve dealt with some of these problems. Recently, as I was refactoring part of our store, I started wishing for a tool that would tell me exactly which parts of the Redux store were being used in any given view, and which parts of the store remained completely untouched by the app. Ideally, I also wanted a way to pause code execution when certain parts of the store were accessed, so I could see exactly how our React component tree related to the Redux state tree.</p><p>I looked around for such a tool, but my search came up empty. So I decided to build it myself — a store enhancer that outputs a report of your Redux usage, aptly named <a href="https://www.npmjs.com/package/redux-usage-report">redux-usage-report</a>.</p><p>Let’s look at how you might use it to audit your Redux store.</p><p><strong>Practical Guide to using Redux-usage-report</strong></p><p>Here’s an example based on a time I wanted to investigate whether the data being passed down from the server in a certain courseProgresses entity was actually used in a particular view of our app.</p><p><strong>1. Add the store enhancer</strong></p><p>Install the redux-usage-report package and add the store enhancer <a href="https://github.com/aholachek/redux-usage-report#1-redux-store-usage-tracker-generatereduxreport">according to the instructions</a>.</p><p><strong>2. Generate the report</strong></p><p>Load the app, perform any user interactions you want to register, and then call reduxReport.generate() in the browser console.</p><p><strong>3. Inspect the </strong><strong>unused part of the report</strong></p><p>The unused object returned by the report shows which parts of the store were never accessed. (All screenshots are from the Chrome devtools).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rrXYVZQnTwPtk11G." /></figure><p>Here, for instance, I see that quite a lot of the courseProgresses data wasn’t needed to render the current view of a course listing page. (If a key is null, that means everything underneath it was not accessed.) It seems that I might want to investigate whether some of the data might be redundant for rendering the current view.</p><p><strong>4. Inspect the </strong><strong>used part of the report</strong></p><p>But which parts of the courseProgresses entities were actually required to render the current view? To answer that question, I can inspect the used key of the report to see which parts of the store were accessed at least once:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KHwqSYfF79ZxToGM." /></figure><p>It seems clear enough that, for the courses that were actually rendered for this page, the only parts of the courseProgresses entity accessed were the started key, and, if that was true rather than false, the percent_complete key as well.</p><p><strong>5. Set a breakpoint</strong></p><p>Say I want to see exactly when the started key is accessed. To do this I can type the following in the console:</p><pre>reduxReport.setBreakpoint(&#39;entities.courseProgresses.bySlug.react-101.percent_complete&#39;)</pre><p>After I reload the page, execution will be paused when that value is accessed, and I’ll be able to go down the call stack and see where it’s used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sXB3hrGt-rAroC8I." /></figure><p>Here, I see that the percent_complete object is passed to the TrackedCourseCard component as a prop called progress.</p><p><strong>How it works</strong></p><p>Since state in a Redux store is an object, I had to figure out how to augment a JavaScript object to track which parts of it were accessed, and provide a<em> diff</em> of the used and unused parts on demand.</p><p>Luckily, ES2015 offers a convenient new API for adding custom functionality to JavaScript objects: Proxies.</p><p><strong>Quick Proxy Interlude</strong></p><p>To quote <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">MDN’s proxy page</a>,“The <strong>Proxy</strong> object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).” Here’s a brief code snippet demonstrating how a very basic proxy works. This one just logs any usage of an object to the console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61dec6489f28d3cb6db84c255fee1715/href">https://medium.com/media/61dec6489f28d3cb6db84c255fee1715/href</a></iframe><p>Redux-usage-report uses proxies, along with some extra code to keep track of what has been accessed. If you’d like to take a look at the full implementation of the library, you can <a href="https://github.com/aholachek/redux-usage-report/tree/master/src">check it out here</a>.</p><p>That’s about all there is to using redux-usage-report. It might be overkill to use it on a small Redux project or one with few developers, but if you are loading a lot of data into your app up front, or if you have a large store and want a better idea of which parts of it are accessed when, give it a try!</p><p>Want to learn more about how we use Redux at Codecademy? Check out my colleague Jon Samp’s <a href="https://medium.com/about-codecademy/react-router-to-redux-first-router-2fea05c4c2b7">article on making the switch to Redux-First-Router</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2e4f31bb86f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/about-codecademy/keep-your-large-redux-application-in-check-with-redux-usage-report-e2e4f31bb86f">Keep your Large Redux Application In Check with Redux-Usage-Report</a> was originally published in <a href="https://medium.com/about-codecademy">About Codecademy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Animations in React From Scratch]]></title>
            <link>https://medium.com/about-codecademy/building-animations-in-react-from-scratch-c66a582c9b65?source=rss-d09f5ddb8967------2</link>
            <guid isPermaLink="false">https://medium.com/p/c66a582c9b65</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Alex]]></dc:creator>
            <pubDate>Thu, 02 Nov 2017 14:58:40 GMT</pubDate>
            <atom:updated>2017-11-02T15:05:04.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*lOQ8olgJdn4v9NQ6." /><figcaption>Transitioning element positions in ComponentDidUpdate</figcaption></figure><p>Recently I was talking with a designer on my team about her vision for a redesign of a certain part of the <a href="https://www.codecademy.com/">Codecademy site</a>. She demoed some very sleek, somewhat elaborate transitions she had been exploring. I immediately started wondering how complex they’d be to implement in our app, which is built in React. Would I have to load in multiple new libraries? Was it even possible in React to do some of the seamless, sequenced animations of elements from one state to another that she was envisioning, without requiring incredibly complex code or awkward hacks?</p><p>Most of the time, when you want an animation in your React app, it makes sense to reach for one of the many libraries that abstract away the details and let you use a declarative style. But sometimes those libraries don’t get you all the way there.</p><p>Maybe you (or the designer you work with) envision a complex series of sequenced animations of multiple elements when a parent component enters and exits the DOM. Maybe you want to animate positions of certain elements as they are re-rendered in different parts of the app. Or maybe you want to take control over the transitions of a continually updating list, a la d3’s enter/update/exit sequence.</p><p>It turns out to be surprisingly feasible to create more complex animation effects in your own code without having to contend with the possible limitations of a React-friendly animation library. You will, however, have to be ok with going slightly against the grain of React. In the examples below, we’ll hook into lifecycle events, making components “impure” by occasionally delaying updates in order to animate elements from one state to another. We’ll also be reaching into the DOM directly using refs.</p><h3>Manipulating the component lifecycle</h3><p>To create certain types of animations, we’ll need to interfere with different parts of the component lifecycle. If we want to animate the removal of elements, for instance, we’ll need a way to delay the removal of nodes from the DOM for the duration of the exit animation. To animate element transitions from point A to point B across the screen, we’ll need to calculate node beginning and ending positions right before the browser paints the change to the screen, and manage layout transitions ourselves.</p><p>Luckily, React offers a variety of lifecycle methods that we can hook into. The method shouldComponentUpdate, which fires when a component receives new props or state, allows us to delay DOM updates until after an exit animation has finished running. If on the other hand we plan to transition elements from one part of the screen to another, we’ll need a way to record the previous positions of the elements right before they are updated. We can use two methods — either componentWillReceiveProps or shouldComponentUpdate to record the previous positions of elements, and then componentDidUpdate to reposition them and smoothly transition them to their new places.</p><h3>Accessing DOM nodes with refs and data-attributes</h3><p>We’ll use a <a href="https://reactjs.org/docs/refs-and-the-dom.html">ref</a> on the parent container to access DOM nodes so that we can animate them. Even though in the examples below the goal is to keep the animation logic and the components fairly decoupled, there are a few caveats.</p><p>First, the wrapped container component must be class-based rather than a functional component, so that we can access its DOM element via a ref. Second, some animations will also require each child to have a unique data-* attribute. (I’ll use data-id.) This attribute will help our animation function distinguish between the children elements and process them correctly.</p><p><strong>Separating animation concerns into a higher order component</strong></p><p>In the examples I’ve used<a href="https://reactjs.org/docs/higher-order-components.html"> higher order components</a> to separate lifecycle animation logic from the presentational logic of components. This is just one possible way of organizing things, and it<a href="https://reactjs.org/docs/higher-order-components.html#refs-arent-passed-through"> adds a bit of complexity when it comes to refs</a>. However, the pattern I’ve used in the examples seems to work fairly well.</p><p>It consists of three parts:</p><ul><li><strong>The presentational components</strong>, here a List and an Item component. They are mostly unaware of the animations, except for two things — as mentioned above the parent List has a ref, so it can’t be functional, and the child Item needs to render a data-id attribute.</li><li><strong>The animation functions</strong> in their own file. I’m using my favorite vanilla JS animation library,<a href="https://github.com/juliangarnier/anime"> anime.js</a> for the actual DOM manipulation. But you could use another JS animation library or CSS transitions and animations.</li><li><strong>The higher order component </strong>that wraps the parent List component and is passed the animation functions. At various parts in the component lifecycle, it calls the appropriate animation function with a ref to the wrapped List component.</li></ul><p>That’s a high-level overview of how the code is structured. Now, let’s look at the examples!</p><h3>One: A basic enter/exit animation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*DdqlGEUupD1i07czqsxGBA.gif" /></figure><p><a href="http://alex.holachek.com/react-animations-from-scratch/?selectedKind=Animation%20Examples&amp;selectedStory=1.%20The%20basic%20technique&amp;full=0&amp;down=1&amp;left=1&amp;panelRight=0">Link to live example</a><br><a href="https://github.com/aholachek/react-animations-from-scratch/blob/master/src/examples/BasicEnterExitExample">Link to code</a></p><p>This example is like a bare-bones version of a <a href="https://reactcommunity.org/react-transition-group/">ReactTransitionGroup</a> that is optimized for calling imperative animations to manage transitions. Here, the parent toggles the isVisible prop to show and hide the child, and the animatingOut state variable makes sure that, even if other updates trigger shouldComponentUpdate before the animation has completed, the exiting elements will be kept in the DOM long enough to transition gracefully.</p><p>I have a setInterval call here updating the element items independent of the entry and exit animations, so that you can see that this setup can handle unrelated updates without hindering the progress of the main animation.</p><p>The HOC wrapper component looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ba110be63217cf39914d92c6ecedb9f/href">https://medium.com/media/8ba110be63217cf39914d92c6ecedb9f/href</a></iframe><h3>Two: Animating component positions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*e3cuuJ1kd2yYqihd0ga6cA.gif" /></figure><p><a href="http://alex.holachek.com/react-animations-from-scratch/?selectedKind=Animation%20Examples&amp;selectedStory=2.%20Object%20persistence&amp;full=0&amp;down=1&amp;left=1&amp;panelRight=0">link to live example</a><br><a href="https://github.com/aholachek/react-animations-from-scratch/blob/master/src/examples/GroupItemsExample">link to code</a></p><p>This example is more complex and provides a better justification for the hand-rolled animation approach. In this animation, there are no elements entering or leaving the DOM. Instead, we want to catch the moment when the groupings have changed, and animate the positions of the children as they move to their new places. For this type of animation, we can use the<a href="https://aerotwist.com/blog/flip-your-animations/"> FLIP technique</a>:</p><ol><li>Record the positions of children right before they are reorganized</li><li>Wait for the browser <a href="https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction">to run layout</a></li><li>Apply transforms to the children in componentDidUpdate, before the changes have been painted, that cause them to return to their pre-update positions</li><li>Initiate transitions to gradually move them back to their updated places</li></ol><p>Below is an example of the animation function that is called twice by the HOC: initially in componentWillReceiveProps, where it stashes the initial positions of the components and returns another function to be called in componentDidUpdate, that will actually handle the transitions with anime.js. As with all of the examples, the component is passed List, the parent ref, by the HOC.</p><h3>Three: D3-style enter, update, and exit animation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*-Jy8nXX-685_P9O9lbAjTA.gif" /></figure><p><a href="http://alex.holachek.com/react-animations-from-scratch/?selectedKind=Animation%20Examples&amp;selectedStory=3.%20Enter%2C%20update%20and%20delete%20transitions&amp;full=0&amp;down=1&amp;left=1&amp;panelRight=0">link to live example</a><br><a href="https://github.com/aholachek/react-animations-from-scratch/blob/master/src/examples/ArrayUpdateExample">link to code</a></p><p>This example combines techniques from the first two — this time, not only are we animating in new elements and delaying updates until we can animate out exiting elements, but we are also waiting for componentDidUpdate to run layout so that we can smoothly animate the updating items to their new positions in the list before the new items appear. The shouldComponentUpdate function is responsible for sorting ids into the three categories of enter, update, and exit, and passing those lists of ids to the respective animation functions, which use the data-id attribute mentioned above to filter the items to the list that they need to animate.</p><p>If you check out the <a href="http://alex.holachek.com/react-animations-from-scratch/?selectedKind=Animation%20Examples&amp;selectedStory=3.%20Enter%2C%20update%20and%20delete%20transitions&amp;full=0&amp;down=1&amp;left=1&amp;panelRight=0">example in storybook</a>, you’ll see a continually updating number rendered under the animation. This is a prop that is being passed through the animation HOC into the List component. Its purpose is to demonstrate that, when lifecycle events are correctly handled, exit animations can proceed as normal even when other sources of data are updating. The way the HOC facilitates this is by caching the old list of elements for the duration of the exit animation.</p><p>The code in the animations file is a also the most complex out of the three examples, partly because I try to account for some edge cases — like fast-forwarding in-progress animations when a new update occurs before the current animation has had a chance to complete.</p><p>It could still stand to be refined, but if you’d like to look at the current implementation for this example, you can <a href="https://github.com/aholachek/react-animations-from-scratch/blob/master/src/examples/ArrayUpdateExample">view the code here</a>.</p><p>Interested in working for Codecademy? <a href="https://www.codecademy.com/about/jobs">Check out our jobs page</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c66a582c9b65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/about-codecademy/building-animations-in-react-from-scratch-c66a582c9b65">Building Animations in React From Scratch</a> was originally published in <a href="https://medium.com/about-codecademy">About Codecademy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>