<?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 Predrag Davidovic on Medium]]></title>
        <description><![CDATA[Stories by Predrag Davidovic on Medium]]></description>
        <link>https://medium.com/@predragdavidovic10?source=rss-ed82561b4afa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QL3TJgzmn0nxYjAGrkNTcQ.jpeg</url>
            <title>Stories by Predrag Davidovic on Medium</title>
            <link>https://medium.com/@predragdavidovic10?source=rss-ed82561b4afa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:19:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@predragdavidovic10/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[Native dual range slider — HTML, CSS & JavaScript]]></title>
            <link>https://medium.com/@predragdavidovic10/native-dual-range-slider-html-css-javascript-91e778134816?source=rss-ed82561b4afa------2</link>
            <guid isPermaLink="false">https://medium.com/p/91e778134816</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[slider]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Predrag Davidovic]]></dc:creator>
            <pubDate>Sat, 02 Apr 2022 03:41:15 GMT</pubDate>
            <atom:updated>2022-04-02T03:41:15.405Z</atom:updated>
            <content:encoded><![CDATA[<h3>Native dual range slider — HTML, CSS &amp; JavaScript</h3><p>Why do we need a dual range slider?<br>Dual range sliders are a popular and practical solution in situations where we need to take a portion of something, for instance: “I want to present products whose prices are in matching range.”</p><p>Unfortunately there is no native HTML5 element which can be used for this concrete purpose. There are plugins which offer solutions, but why always rush for plugins when you can implement it yourself.<br>In this tutorial we will use HTML &lt;input type=&quot;range&quot; /&gt; , CSS to make it looks as we want, and vanilla JavaScript to make it works properly.</p><p>Final output will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*xS4WSGC4UunAmR916RfR3g.gif" /><figcaption><a href="https://codepen.io/predragdavidovic/pen/mdpMoWo">https://codepen.io/predragdavidovic/pen/mdpMoWo</a></figcaption></figure><p>Now let’s start from the beginning.<br>How our range sliders look without any CSS and JS is presented in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*LcDMSWOmbpzi7cCiwS29Sg.png" /><figcaption>Range Sliders without CSS</figcaption></figure><p>Above image shows our initial step. The HTML shown on the above image is our final HTML version and it is presented here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9847627e7e2f53ca43415d4725262b40/href">https://medium.com/media/9847627e7e2f53ca43415d4725262b40/href</a></iframe><p>Now we need to customize it using CSS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2210b686ebfaee057cbf1e3ce0886b9/href">https://medium.com/media/a2210b686ebfaee057cbf1e3ce0886b9/href</a></iframe><p><strong><em>.range_container, .sliders_control, .form_control, input[type=”number”]</em></strong><em> </em>are selectors which are self explanatory and there is no need to write about them.<br><strong><em>input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button</em></strong> is used to constantly show up and down arrows next to input numbers.</p><p><strong><em>input[type=range]::-webkit-slider-thumb</em></strong> selector is used to customize thumbs in the desired way. <br><em> </em><strong><em>-webkit-appearance: none;</em></strong> is used to remove platform specific styling appearance and then we can customize it as we want. <strong><em>::-moz-range-thumb </em></strong>selector is used to apply appearance changes on Mozilla firefox.</p><p>And the most interesting part is <strong><em>input[type=”range”]</em> </strong>selector<strong>.<br></strong>Firstly we use <strong><em>appearance: none;</em> </strong>to remove platform specific styling and do our own customization.<br><strong><em>position: absolute;</em> </strong>instruct two sliders to overlap each other and we got one slider with two thumbs.<br>To customize slider appearance <strong><em>background-color</em></strong> is used, this property will be used by JavaScript customization.</p><p>And with given HTML and CSS we got following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qx9oEiYRSLw07ppzEmI-6g.gif" /></figure><p>Everything looks good, but nothing works. :-)</p><p>Now we need to add JavaScript to put everything in order.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/634a72e4d027fd4afff2c2da6a8ee6b7/href">https://medium.com/media/634a72e4d027fd4afff2c2da6a8ee6b7/href</a></iframe><p>Firstly we got four controllers:<em> fromSlider, toSlider, fromInput, toInput.</em><br>The <strong><em>fillSlider</em></strong> function is called first. Function is used to fill the range between thumbs with appropriate color initially and on each slider move. In function we get distance and color it with desirable color. The remainder of the slider is colored gray.</p><p>Subsequently <strong><em>setToggleAccessible</em></strong> is called. This function has only one mission to set <strong><em>zIndex</em> </strong>of <strong><em>toSlider</em></strong> element<strong> </strong>bigger than <strong><em>zIndex</em></strong> of <strong><em>fromSlider</em></strong> in situation when <strong><em>toSlider</em></strong> has value zero. <br> That situation is presented only when we move <strong><em>toSlider</em></strong> to zero or if the initial value of <strong><em>toSlider</em></strong> is zero.<br> Initially <strong><em>fromSlider</em></strong> has stronger <strong><em>zIndex</em></strong> and it will always overlap <strong><em>toSlider</em></strong> and that is desirable behavior, however in situations when they both have zero value we need toSlider to become stronger in other words <strong><em>toSlider</em></strong> thumb should overlap <strong><em>fromSlider</em></strong> thumb.</p><p>And lastly on each controller we set up listener which will react on every change. All controllers are similar by what they are doing. <br> They got current values and color sliders with current values. Also control <strong>from</strong> value to never exceed <strong>to</strong> value, and vice versa.</p><p>There are different approaches in building dual slider, this one was interesting for me at this time. If you have any questions feel free to write it in comments section. Until next article, keep rocking.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91e778134816" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useMemo why, when & how]]></title>
            <link>https://medium.com/@predragdavidovic10/usememo-why-when-how-e045b7dade82?source=rss-ed82561b4afa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e045b7dade82</guid>
            <category><![CDATA[usememo]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Predrag Davidovic]]></dc:creator>
            <pubDate>Tue, 02 Nov 2021 15:22:47 GMT</pubDate>
            <atom:updated>2021-11-02T15:22:47.140Z</atom:updated>
            <content:encoded><![CDATA[<p>Idea of the article is to be concise and give the most important information about the mentioned technique.</p><p><strong>Why</strong>, <strong>When</strong> and <strong>How</strong> are questions which we should try to answer each time we encounter something new in our technology journey.</p><p>Before we continue, let’s discuss what useMemo is.<br>useMemo is used to return <em>memoized </em>value from function provided from our side.</p><blockquote><em>In </em><a href="https://en.wikipedia.org/wiki/Computing"><em>computing</em></a><em>, </em><strong><em>memoization</em></strong><em> or </em><strong><em>memoisation</em></strong><em> is an </em><a href="https://en.wikipedia.org/wiki/Optimization_%28computer_science%29"><em>optimization</em></a><em> technique used primarily to speed up </em><a href="https://en.wikipedia.org/wiki/Computer_programs"><em>computer programs</em></a><em> by storing the results of expensive </em><a href="https://en.wikipedia.org/wiki/Subroutine"><em>function calls</em></a><em> and returning the cached result when the same inputs occur again. (Wikipedia source).</em></blockquote><p>As we can see from the previous definition useMemo is used to boost our performance. We covered the Why question from our title.</p><p>Next question which pops up is: <strong>When </strong>should we use useMemo?<br>useMemo should be used in two cases:</p><ul><li>To remember result from expensive computation</li><li>To skip expensive re-render of a child component</li></ul><p><strong>How</strong> is the biggest part of our article and we will do it through examples. Examples will not be expensive computations but it will serve as executable examples.</p><figure><img alt="useMemo code snippet" src="https://cdn-images-1.medium.com/max/720/1*MRW897YDsXqF8HufOihXRQ.png" /><figcaption>Editable example: <a href="https://codesandbox.io/s/usememo-expensive-calculation-u74fy?file=/src/App.js">https://codesandbox.io/s/usememo-expensive-calculation-u74fy?file=/src/App.js</a></figcaption></figure><p>Input field is handled by handleChange function.<br>Last digit from inserted value from Input field is set into state.<br>State value (number) is used in “expensive calculation”.<br>After doing “expensive calculation” the result is memoized and the component is rendered.<br>In the next iteration we type a number into the input field, if the number is the same as the previous one “expensive calculation” wouldn’t take place and instead the memoized value will be returned.<br>And that is it, if the value passed to the memoized function is the same as the previous one, the memoized value is returned. Dependency array is a place where we put values from which our calculation is dependent. In the above snippet, the number is only a dependent value.</p><p>Another use case of memoization is used in situations where we want to prevent unnecessary rendering of child components when something changed in parent.</p><figure><img alt="useMemo code snippet" src="https://cdn-images-1.medium.com/max/852/1*gjmFIXRqSbia6Z2hYse_Rw.png" /><figcaption>Editable example: <a href="https://codesandbox.io/s/usememo-render-child-evpts">https://codesandbox.io/s/usememo-example-evpts?file=/src/App.js</a></figcaption></figure><p>When parent component change state, default behaviour cause re-render of all child components. That behaviour could be prevented by memoization of the child component.<br>In our code snippet on each keystroke Parent component change state which causes the ChildComponent to be re-rendered, but MemoizedChildComponent return cached value without doing re-rendering.<br> In this way we preserve our expensive re-rendering from occurring and serve cached value.</p><p><strong>Conclusion: <br></strong>We use useMemo to boost our performance by using cached values. Cached values are used in situation when inputs values has the same value as the value in previous render. Make hands dirty by using above examples and write comments if something is unclear.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e045b7dade82" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>