<?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 Ilan Roitlender on Medium]]></title>
        <description><![CDATA[Stories by Ilan Roitlender on Medium]]></description>
        <link>https://medium.com/@ilanroitlender?source=rss-2c14ae3a0838------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tUKKU9_rhEAnIxi4.</url>
            <title>Stories by Ilan Roitlender on Medium</title>
            <link>https://medium.com/@ilanroitlender?source=rss-2c14ae3a0838------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:35:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ilanroitlender/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[React makes building UI easy. Here’s why.]]></title>
            <link>https://medium.com/meliopayments/react-makes-building-ui-easy-heres-why-2e7bad0c3b21?source=rss-2c14ae3a0838------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e7bad0c3b21</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[melioengineering]]></category>
            <dc:creator><![CDATA[Ilan Roitlender]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 10:28:38 GMT</pubDate>
            <atom:updated>2023-08-01T09:18:51.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*HDZrBk6dAumpQ2CjYLvYTA.png" /></figure><p>This year we’re going to celebrate React’s 10 year anniversary! Since it was open-sourced, it has been dominating front-end development. React has become the most used web framework among global software developers since 2021. It makes sense since comparatively, it’s easier to learn, it’s uncomplicated to use, maintain and test, it’s efficient, performs well, and has a rich user interface. According to <a href="https://www.similartech.com/technologies/react-js">SimilarTech</a>, 1,345,024 websites have been built with React as of March 2023.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*muS23zwUchbW2CMNDAxc3g.png" /><figcaption>Top websites using React (SimilarTech)</figcaption></figure><p>In this blog, we are going to discuss why React has become a popular choice for front-end development and how to prioritize user experience with some practical examples.</p><p>I am going to concentrate on two features and ideas to help you improve your user experience and your development process. Let’s dive in.</p><h4><strong>Lazy loading — how are you?</strong></h4><p>React lazy loading is a technique that has become increasingly popular among front-end developers in recent years. It involves splitting your application’s code into smaller chunks, or modules, which are loaded on-demand instead of all at once. In this section, we’ll discuss why lazy loading is considered good practice for front-end developers, how it works behind the scenes, and some examples of how it can improve the performance of your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JsCkCE4tZFhTYR4J" /></figure><p>First and foremost, lazy loading allows developers to significantly reduce the initial load time of their applications. When a user opens a webpage, the entire codebase of the application must be downloaded and executed by the browser. This process can take several seconds or more, especially if the application is large or complex. By splitting the code into smaller, more manageable modules and loading them only when they are needed, developers can reduce the initial load time of their application and improve the overall user experience.</p><blockquote>Behind the scenes, lazy loading works by utilizing the dynamic import() function in JavaScript. This function allows you to load a module asynchronously, meaning that it will not block the main thread of execution while it is being loaded. Instead, the module will be loaded in the background and then executed once it has been fully loaded. This can be especially useful for larger modules or modules that are only needed in certain parts of the application.</blockquote><p>Splitting up your app into several chunks comes with several challenges, like deciding what to put in each chunk and when to download it so the user will have a smooth experience.</p><h4><strong>How to use it</strong></h4><p>One example of how lazy loading can be used in practice is with React Router. By lazy loading the components that are associated with specific routes, you can ensure that only the code that is needed for each individual page is loaded. This can be a significant improvement over loading all of the components for your entire application upfront, especially if your application has many different routes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KtExfJrVUFfjh_Je" /><figcaption>Simple react entry application</figcaption></figure><p>In this example, we can see a simple application that renders two routes. The first route that the user will see is the <em>HomePage </em>and only if they will navigate to <em>/customer,</em> the browser will load the rest of the code so the user will see the customer page.</p><h4>Eager VS lazy loading showcase</h4><p>Let’s say our requirement is to generate and display a preview of a client receipt PDF file when a user clicks on the button and we know that this feature isn’t used very often by the client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AyCiAerCb6RhmT142-6P5w.gif" /></figure><p>For this implementation, we will use some third-party libraries that may increase our bundle size and following this, we may increase the load time for the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELYdFscFnjbzQg6dnzwXkA.png" /><figcaption>Third-party libraries usage</figcaption></figure><h4>Eager loading</h4><p>The first approach involves importing the component as soon as we load the page — without splitting it into multiple chunks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wic5p7vYzFaFu-pKF1-S7Q.png" /><figcaption>Eager loading</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3yk8jaMa-mjV5hLYbtL2jA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gDl1Iv1LbfOvhoYtleMuA.png" /><figcaption>bundle size is 585kb</figcaption></figure><p>When we load the page for the first time, all js code is downloaded at once even if currently we are not consuming the content.</p><h4>Lazy loading</h4><p>Let&#39;s make small changes so we can split our application into several chunks. That way, we reduce the initial load time of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WEw5fd8G36IdZQGhHIpWEg.png" /><figcaption>Components lazy loading</figcaption></figure><p><strong>Let&#39;s break it down</strong></p><pre>const SomeExpensiveComponent = React.lazy(<br>  () =&gt; import(/* webpackChunkName: &quot;this_is_expansive&quot; */ &#39;components/SomeExpensiveComponent&#39;)<br>);</pre><blockquote>Line 6 we replaced the import with `<em>React.lazy`</em>, by doing so react will not import the component untill it will be used. Webpack supports a special commenting syntax called “magic comments”, which lets you name the different chunks. The bundles we load work fine as is, but they’re not really aptly named. 0.chunk.js and 1.chunk.js might get the job done, but it’s not great for debugging errors in production.</blockquote><pre>&lt;React.Suspense fallback={&lt;CircularProgress msg=&quot;Loading...&quot; /&gt;}&gt;<br>        {showExpensiveComponent &amp;&amp; &lt;SomeExpensiveComponent /&gt;}<br>&lt;/React.Suspense&gt;</pre><blockquote>Line 28 we’re wrapping the &lt;SomeExpensiveComponent /&gt;component in a &lt;Suspense&gt; component and specifying a fallback UI to be shown while the component is being loaded. In this case, we&#39;re simply rendering a loader with &quot;Loading...&quot; message.</blockquote><blockquote>Simple as that React will handle all asynchronous complexity.</blockquote><p><strong>Final result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f83iDyddmBC6Jj0etuuYhA.gif" /><figcaption>this_is_expansive.chunk.js has been downloaded only when the user clicks on the download button.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0rIhSqLS-7F28P2iuwakA.png" /><figcaption>Initial bundle size reduced to 521kb</figcaption></figure><p><strong>Let’s use it everywhere (?)</strong></p><p>So the short answer is <strong>NO</strong>. Let me explain: When building a great UI, the application should be responsive and snappy. When we choose to split our application code into multiple little chunks, we need to remember that every time the user clicks and tries to consume the content for the first time, it will lazy load the specific chunk of code. Until it’s done, it will show the default fallback component that we defined in our Suspense component. So in a case where we have multiple chunks, it will show several loaders on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*y1cX76JY8S7_1Lf_olFJwA.gif" /><figcaption>Spinners everywhere.</figcaption></figure><h4>How we use it at Melio</h4><p>Our Tools team at Melio serves a lot of different teams cross-organizationally and each team has its own roles and permissions. For example, Team A will use only specific apps from the Tools product so when the application loads, there is no reason to load all other applications. This will significantly reduce the bundle size and helps to improve overrule user experience.</p><blockquote>In conclusion, <strong>be lazy </strong>(not really).</blockquote><p>Lazy loading is a powerful technique that can help improve the performance of your front-end application. By breaking your code into smaller, more manageable chunks and loading them on-demand, you can reduce load times, save bandwidth, better manage the complexity of your code, and provide a better user experience. When used appropriately, lazy loading can be a powerful tool for optimizing the performance of modern web applications.</p><p>If you’re a front-end developer, it’s definitely worth considering how you can incorporate lazy loading into your own projects.</p><h4>Bonus</h4><p>At the beginning of the blog, I mentioned that I was going to talk about two main features. So now it’s time to talk about error handling in React.</p><p>If you are a React developer, you may have come across a situation where your application crashes due to unhandled errors in your components. This can be frustrating for both the developer and the end user. To tackle this problem, React provides a feature called ErrorBoundary.</p><p>ErrorBoundary is a React component that catches errors in its child components and displays a fallback UI instead of the crashing component tree. This way, your application can recover gracefully from errors, and the user can continue using it without disruption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*NaSpZRu4HazzriGevn4SEA.png" /><figcaption>Catch errors like a pro.</figcaption></figure><h4>Catch, display, and log</h4><p>One of the main benefits of ErrorBoundary is its ability to catch errors that occur during rendering. When an error is detected, ErrorBoundary will display a fallback UI instead of the crashed component. This not only prevents your application from crashing entirely but also provides a better user experience by showing a message or alternative content. ErrorBoundary can also be used to catch errors in event handlers, lifecycle methods, and other parts of your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ibmc-dBpS-d4SmUdAsdhtQ.gif" /><figcaption>Display fallback UI for better UX.</figcaption></figure><p>This fallback can be applied on smaller components of the UI so in case one of the wrapped components will throw, it will not break the entire UI, and the rest of the page will run normally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOEmsbo5rB2E76mLT9MixA.gif" /><figcaption>By wrapping each component individually we insure that the page will continue to run even in case one of the component gets a js error.</figcaption></figure><p><strong>Let&#39;s dive into the code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uL3rS2kNnchVqJy6LGqgCg.png" /></figure><blockquote>A class component becomes an error boundary if it defines either (or both) of the lifecycle methods <a href="https://legacy.reactjs.org/docs/react-component.html#static-getderivedstatefromerror"><em>static getDerivedStateFromError()</em></a> or <a href="https://legacy.reactjs.org/docs/react-component.html#componentdidcatch"><em>componentDidCatch()</em></a>. Use <em>static getDerivedStateFromError()</em> to render a fallback UI after an error has been thrown. Use <em>componentDidCatch()</em> to log error information. [react.org documentation]</blockquote><p>In this example, we provide a generic component that can receive a fallback component and in case of an error, will render it instead of this.props.children.</p><p>In addition to catching errors, ErrorBoundary also provides a way to log those errors to an API or another external service. This is important for debugging and troubleshooting your application. By logging errors, you can get a better understanding of what’s causing them and take steps to prevent them from happening in the future. This can be especially useful in production environments where it may be difficult to replicate the error.</p><pre>override componentDidCatch(error, errorInfo) {<br>    this.setState({<br>      hasError: true,<br>      error<br>    });<br>    // API service we use to provide information about the error<br>    logger.error(error, { errorInfo }); <br>}</pre><blockquote>Great third-party API services that provide log management such as Data-dog and Sentry can save a lot of time and money when issues come up in production.</blockquote><p>To use ErrorBoundary in your application, simply wrap the components or parts of your application that you want to protect with the ErrorBoundary component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5OWb_YfaGqzJ4ug0nmzAA.png" /></figure><p>In summary, React ErrorBoundary is an essential tool for any engineer building complex React applications. Its ability to catch errors, display fallback UI, and log errors to an API makes it an essential part of your application’s error-handling strategy. By using ErrorBoundary, you can improve the reliability and stability of your application, and provide a better user experience for your users.</p><h4>Let&#39;s wrap it up</h4><p>Throughout this post, we explored some important concepts of React, such as React.lazy, React.Suspense and ErrorBoundary component. Whether you’re a beginner or an experienced React developer, there is always more to learn, and I encourage you to continue exploring and experimenting with this framework.</p><p>Thank you for reading 💜</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qSivDZI-3fRph6erM7GtQ.png" /><figcaption><a href="https://bit.ly/jobs-medium">Visit our career website</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e7bad0c3b21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/meliopayments/react-makes-building-ui-easy-heres-why-2e7bad0c3b21">React makes building UI easy. Here’s why.</a> was originally published in <a href="https://medium.com/meliopayments">Melio’s R&amp;D blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Ways to pass data between components using React API]]></title>
            <link>https://medium.com/weekly-webtips/5-ways-to-pass-data-between-components-using-react-api-fc4f96868f05?source=rss-2c14ae3a0838------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc4f96868f05</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ilan Roitlender]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 08:46:48 GMT</pubDate>
            <atom:updated>2020-06-05T18:17:12.252Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKFYFHwdsCzX2uo_QJqoLQ.jpeg" /></figure><p>React is a powerful library that makes your development experience fun and fast so you can focus on building modern, interactive web applications but with a great ( and powerful ) API comes great responsibility.</p><h3>Thinking in React</h3><p>The first thing that comes in mind when building new screen in react application is to break the UI into component hierarchy with small components. It will help you share, organize and reuse components between apps and projects.</p><blockquote><strong>We talked about breaking down the components but what about sharing data and methods between components?</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a63ddd4013b63604d014b9f6bf84febe/href">https://medium.com/media/a63ddd4013b63604d014b9f6bf84febe/href</a></iframe><p><em>Here we can see a component that simply render to the screen paragraph that shows the current mouse position.</em></p><h4>The problem</h4><p>We are reusing our components piece by piece but what about props and data?</p><p>Lucky for us React API comes to the rescue and give us a various options to help us reduce the amount of duplicate code, keep our code as much reusable as possible and shrink your lines of code.</p><ol><li><a href="https://reactjs.org/docs/react-api.html#cloneelement">React.cloneElement </a><strong>to the rescue</strong>:<br>This is a Top-Level-API, that receives a react element and makes a shallow copy of the element and returns a new element that contains the original element’s props as well the new props attached to it.<br>React.cloneElement() is almost equivalent to:<br>&lt;element.type {...element.props} {...props}&gt;{children}&lt;/element.type&gt;</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9689901bb9fa2b3dc88b9a46fad482/href">https://medium.com/media/cf9689901bb9fa2b3dc88b9a46fad482/href</a></iframe><blockquote>Use React.Children.map method to create new array of elements (children) and attach additional props to each component.</blockquote><p><strong>Why should we use this approach? <br>- </strong>Well, the simple response is we should not. React evolved so much in the past few year so I cant see any good reason to use it when React is giving you many and better options to play and experiment with, but still its good to know about this API in case you will need it.</p><p>2. <a href="https://reactjs.org/docs/render-props.html">renderProp</a>s — <strong>Passing values using functions</strong><br>Every React developer come across with this method, for example if you ever used libraries like <a href="https://reacttraining.com/react-router/web/api/Route/render-func">React Router</a>, <a href="https://github.com/jaredpalmer/formik">Formik</a> or <a href="https://github.com/bvaughn/react-virtualized">React-virtualized</a>.</p><blockquote>Note, If you are using static type checking library, its important to explicitly the children type, Since this technique is a little unusual- the children that passed to the component should be of type Function.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb596f8812c5548988265850f7619267/href">https://medium.com/media/eb596f8812c5548988265850f7619267/href</a></iframe><blockquote><em>note: I`m using </em><em>React.useCallback to memorize the function.</em></blockquote><p>3. <strong>Using </strong><a href="https://reactjs.org/docs/higher-order-components.html">Higher-Order-Components</a> <strong>to render props</strong>:<br>HOC is an advanced technique in React that helping us as developers to reuse components logic, as before you may come across in a third-party React libraries, such as Redux’s connect method.<br>A HOC function takes a component as an argument and returns a component. It transforms a component into another component and adds additional data or functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d953c79285e1dc78a68516463d77941b/href">https://medium.com/media/d953c79285e1dc78a68516463d77941b/href</a></iframe><blockquote>mouseHOC receive App component and returns it with new prop mousePos.</blockquote><p>4. <strong>Using Custom hooks </strong>useMousePos :<br>As I said before React is evolving all the time and without any doubt one of my favorite new additions is the use of new <a href="https://reactjs.org/docs/hooks-custom.html"><strong><em>React Hooks API</em></strong></a> since React 16.8 .<br>Until now renderProps and HOC was the most common ways to share logic between components and the down side was that you required to add more components to your components tree.</p><p><em>This is a simple implementation of creating custom hook in our scenario comes in handy:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/544d95b67b475e31c9bafd7c44a867c6/href">https://medium.com/media/544d95b67b475e31c9bafd7c44a867c6/href</a></iframe><blockquote>useMouseHook receive reference to node container and attached an EventListener so it can update state and return the current mouse position.</blockquote><blockquote>Note, do not forget to add cleanup function to prevent memory leeks.</blockquote><p>5.<strong> Using </strong><a href="https://reactjs.org/docs/context.html"><strong>Context API</strong></a><strong> :</strong><br>React Context can be a great state management solution for React applications. It helps you to contain and handle application global state for small and large scale apps. By using Context you are passing down the components tree any prop or data without prop drilling.</p><p>context does NOT have to be global to the whole app, but can be applied to one part of your tree and you can (and probably should) have multiple and separated contexts in your app.</p><blockquote>Note, this is a simple case and you are probably not going to use it to pass props like mouse position, in this example that I’m intentionally over-engineering to show how we can achieve the same goal like in other examples.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e38fde2ad05a309f7d024205abd41012/href">https://medium.com/media/e38fde2ad05a309f7d024205abd41012/href</a></iframe><blockquote>By wrapping component with contextPropvider, any nested child down the tree can access the Context state using usePosContext() .</blockquote><p><strong>Sandbox playground:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fdreamy-sea-v50z1%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fdreamy-sea-v50z1%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fv50z1%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca708389c712b380e7ddd19561efafd/href">https://medium.com/media/7ca708389c712b380e7ddd19561efafd/href</a></iframe><h3>Conclusion</h3><p>When starting building new features to our existing apps or planning UI Design, its important to start separate it into smaller sub components. Same goes about our data modal, methods and little pieces of data that are going to be shared between components.</p><p>React is a simple JavaScript library for building user interfaces, the API is very flexible and giving you a set of tools for quicker, easier and straightforward development.</p><p>To summarize with a personal note, In my opinion creating a custom hooks can solve many of the same problems with much cleaner syntax and without forcing you to add more components to the tree.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc4f96868f05" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/5-ways-to-pass-data-between-components-using-react-api-fc4f96868f05">5 Ways to pass data between components using React API</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>