<?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 Silvio Biasiol on Medium]]></title>
        <description><![CDATA[Stories by Silvio Biasiol on Medium]]></description>
        <link>https://medium.com/@biasiol.silvio?source=rss-e93049d630a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*P7IBY-UGKB-qBBzw</url>
            <title>Stories by Silvio Biasiol on Medium</title>
            <link>https://medium.com/@biasiol.silvio?source=rss-e93049d630a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:52:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@biasiol.silvio/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 Hooks Emoji Search]]></title>
            <link>https://medium.com/@biasiol.silvio/react-hooks-emoji-search-1889f3aabedc?source=rss-e93049d630a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1889f3aabedc</guid>
            <dc:creator><![CDATA[Silvio Biasiol]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 20:13:19 GMT</pubDate>
            <atom:updated>2019-04-08T20:13:19.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*dXFK3vW7hI9ppTKlq61j4w.png" /></figure><p>Hi everybody! I’ve been recently searching a good site where I could look up and copy emoji very quickly (<a href="https://emojipedia.org/">Emojipedia </a>is good but kind of cumbersome) to bother my coworkers with colorful commit messages 🌈.</p><p>Since I didn’t find anything that could satisfy my emoji’s hunger 💩 I ended up developing it by myself and I’d like to show you how I did it! Here’s how the end result will look like:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F8kpmxjk5w2%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F8kpmxjk5w2%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F8kpmxjk5w2%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/f5a8dc06a4b76681cabc20e0b47c92e1/href">https://medium.com/media/f5a8dc06a4b76681cabc20e0b47c92e1/href</a></iframe><p>If you are an impatient nerd 🤓 you can directly take a look or edit the code on codesandbox, otherwise just follow along.</p><p>I have decided to develop the main component using <a href="https://reactjs.org/docs/hooks-intro.html">React Hooks</a> (why not?) since I find hooks syntax much lighter and less complex than traditional React components.</p><p>Without further ado let’s delve into the code 👨‍💻</p><p>Here’s the React Hooks core part:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85194e27107b1ea0aa1122910f453330/href">https://medium.com/media/85194e27107b1ea0aa1122910f453330/href</a></iframe><p>The component state is composed by the above state variables and their update methods:</p><ul><li>emojiList contains all the emoji</li><li>activeEmoji contains the emoji filtered by our search bar</li><li>copied contains the last emoji copied on the clipboard</li><li>visible shows or hides the alert of successful copy</li></ul><p>We need an API to fetch the emoji, I have used <a href="https://www.npmjs.com/package/emoji.json">emoji.json</a> npm package <a href="https://unpkg.com/emoji.json@11.0.1/emoji.json">fetchable list</a> (thank you 💖) which exposes a JSON endpoint with this list:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68d609e67609920303967fed5ec378ce/href">https://medium.com/media/68d609e67609920303967fed5ec378ce/href</a></iframe><p>So we will need to fetch this list using the useEffect method. If you don’t know how to fetch a resource with React Hooks here’s a <a href="https://www.robinwieruch.de/react-hooks-fetch-data/">nice article about it</a>. Here’s the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0404c080b21267b7c01c82064d7068cb/href">https://medium.com/media/0404c080b21267b7c01c82064d7068cb/href</a></iframe><p>What does it do?</p><ol><li>First the <a href="https://reactjs.org/docs/hooks-effect.html">effect hook</a> is used to fetch the data from the API</li><li>Then the JSON is parsed from the retrieved data</li><li>Finally we set the emojiList and activeEmoji in the local state of the component with the state hook’s update functions. Since when the page is loaded the search bar is empty we set activeEmoji to display all the emoji.</li></ol><p>The main content of our page will then be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/547a1f6f93f6c092c0b1df9782c29a63/href">https://medium.com/media/547a1f6f93f6c092c0b1df9782c29a63/href</a></iframe><p>While the emoji list is being fetched the app shows a loading screen. If the search string doesn’t match any emoji the app shows a sad face followed by a message. Finally if we found some emoji we show all of them.</p><p>The handleCopyToClipboard method carries out several operations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f9670a9bdc029939b56157f3225438c/href">https://medium.com/media/3f9670a9bdc029939b56157f3225438c/href</a></iframe><ol><li>Append a temporary DOM node to the document body and assign as its value the copied string</li><li>Use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand">Document.execCommand(</a>) API to copy this value</li><li>Remove the node from the body</li><li>Updates the component state with the state hook’s update functions saving the copied value and showing temporarily the successful copy message</li></ol><p>So we have the content but we now need the search bar 🕵</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a913c4a42c1117d08d90209ed96c7806/href">https://medium.com/media/a913c4a42c1117d08d90209ed96c7806/href</a></iframe><p>The search bar triggers the handleSearchInputChange when its value changes. This function takes the new value of the search bar input and tries to match it against or emoji list keywords updating the activeEmoji array with the found matches. If the searchbox is empty it simply resets activeEmoji to the initial list.</p><p>The onDismiss function hides the alert message when the ✕ button is pressed</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbca33695df014672a1747882edee685/href">https://medium.com/media/bbca33695df014672a1747882edee685/href</a></iframe><p>Now we just need to add <a href="https://gist.github.com/silvioBi/6c439ee66d116e3f83d1939e0a58b231">a little bit of css</a> and the job is done!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*For-F6vfiLDUOckB8TSm9A.gif" /></figure><p>You can take a look at the <a href="https://codesandbox.io/s/8kpmxjk5w2?fontsize=14">editable live demo</a> here or you may navigate to the <a href="https://github.com/silvioBi/emoji-list">repository</a> and clone or download the code from there.</p><p>Hope you enjoyed the article and if so don’t forget to 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1889f3aabedc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React images lazy load]]></title>
            <link>https://medium.com/@biasiol.silvio/react-images-lazy-load-c9b38782ed93?source=rss-e93049d630a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9b38782ed93</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Silvio Biasiol]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 13:46:22 GMT</pubDate>
            <atom:updated>2019-04-01T13:46:22.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIpY_71gLVHYjznGh8glNw.jpeg" /></figure><p>This is my first post on Medium, I’m so excited and I want to share with you how I developed an images lazy loader with React. It would have not been possible without the cool articles <a href="https://medium.com/walmartlabs/lazy-loading-images-intersectionobserver-8c5bff730920">Lazy Loading Images with IntersectionObserver</a> by <a href="https://medium.com/@parkjoon94">Joon Park</a> and <a href="https://scotch.io/tutorials/lazy-loading-images-for-performance-using-intersection-observer">Lazy Loading Images for Performance Using Intersection Observer</a> by <a href="https://scotch.io/@codebeast">Chris Nwamba</a>, in fact most of the code of the component is from these two articles with some tweaks and adjustments. So without further ado here’s how the end result will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*7BRK3mDEQDDD_ZsOtM88xg.gif" /><figcaption>Some lazy loaded images (using a slow 3G connection)</figcaption></figure><p>I decided to add two kind of loading effects while the image is being fetched. The first is the effect explained in <a href="https://scotch.io/tutorials/lazy-loading-images-for-performance-using-intersection-observer">Chris Nwamba article</a>, that is using a very low quality version of the image that we want to load as placeholder. The second effect is achieved using a simple grey div that keeps glowing (credit to <a href="https://codepen.io/nidhinobinu">nidhin</a> <a href="https://codepen.io/nidhinobinu/pen/RWaYGb">script on CodePen</a>).What you use is up to you 😎.</p><p>In order to avoid DOM size issues the wrapper container that I have used to contain the image has its same height and width. The placeholder acts as an overlay to the original image that is initially hidden. The render method for the component is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bae335b8f77ea5b16f860fffae95ff0/href">https://medium.com/media/1bae335b8f77ea5b16f860fffae95ff0/href</a></iframe><p>We save the <a href="https://reactjs.org/docs/refs-and-the-dom.html">React Refs</a> of the placeholder and the image, to hide the former and show the latter once the image is fetched. If we provide the URL of the placeholder image to the component(placeholderSrc property) than the placeholder image is shown while fetching the image, otherwise the glowing overlay is shown instead.</p><p>The core logic is in the componentDidMount method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f183118739855f85a483e06a767205e3/href">https://medium.com/media/f183118739855f85a483e06a767205e3/href</a></iframe><p>Okay, so there is a lot going on here 🔥</p><p>We use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API">Intersection Observer API</a> which as the name suggests “<em>provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document’s viewport</em>”.</p><p>Since we have not specified any options our observer will use as target the top-level document’s <a href="https://developer.mozilla.org/en-US/docs/Glossary/viewport">viewport</a>. It will launch loadImage(which I will explain in the next section) when at least one of the arguments of observer.observe enters the viewport (in our casethis.image)</p><p>“How is loadImage implemented?” You might ask</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fd8470ab6e9d08a6ca089e52cf1a829/href">https://medium.com/media/9fd8470ab6e9d08a6ca089e52cf1a829/href</a></iframe><p>It takes as arguments the image and placeholder refs and the URL of the image to fetch. Once the image is retrieved byfetchImage (that fetches it and returns a promise) loadImageupdates the src and opacity of the image and hides the placeholder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*vPJw-hzxSqt7Pys_bU5gWQ.gif" /></figure><p>Now all we need it’s a little bit of css and that’s it 🎉</p><p>Here’s the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2645ccc21b3a5c7dd80dff1a07ec0d3/href">https://medium.com/media/c2645ccc21b3a5c7dd80dff1a07ec0d3/href</a></iframe><p>Hope you liked this article! You can find all the code along with instructions on <a href="https://github.com/silvioBi/lazy-load-images">the repository</a>.</p><p>Have a nice day ✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9b38782ed93" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>