<?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 Oscar Oscar on Medium]]></title>
        <description><![CDATA[Stories by Oscar Oscar on Medium]]></description>
        <link>https://medium.com/@bakkeroscar?source=rss-19b874ffe6b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zT1RqFAtagQ30S8z.jpg</url>
            <title>Stories by Oscar Oscar on Medium</title>
            <link>https://medium.com/@bakkeroscar?source=rss-19b874ffe6b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 20:55:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bakkeroscar/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[Create your own Redux selectors using memoization.]]></title>
            <link>https://medium.com/@bakkeroscar/create-your-own-redux-selectors-using-memoization-c112facd2eb?source=rss-19b874ffe6b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c112facd2eb</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reselect]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Oscar Oscar]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 16:12:34 GMT</pubDate>
            <atom:updated>2018-04-22T16:12:34.754Z</atom:updated>
            <content:encoded><![CDATA[<p>The goal of this article is to give a basic explanation about how selectors like reselect work in an application that uses Redux.</p><p>Working with React and Redux is a great experience, but having some lower level knowledge of how these tools work is mandatory on larger projects.</p><p>When I first started using Redux, selectors came to my attention. Selectors are functions that return a part of your state, a selection. Because these functions could get abused by unexpected rerenders or something else, we should use them with care. Their result can be cached quiet easily, that’s where reselect and re-reselect enter the arena.</p><p><a href="https://github.com/reactjs/reselect">https://github.com/reactjs/reselect</a></p><p>Sound great and I would definitely use them, but for this story I am gonna write my own very basic caching function.</p><pre><strong>function </strong>mapStateToProps(state) {<br>  <strong>return </strong>{<br>    <strong>schools</strong>: state.schools,<br>    A<strong>mericanSchools</strong>: selectSchoolsByCountry(&#39;USA&#39;, state.schools),<br>  }<br>}</pre><p>The function <strong>selectSchoolsByName</strong> selects a part of the state.schools. AmericanSchools is a selectors of state.schools.</p><pre><strong>function </strong>memoizeSelection(keyProp) {<br>  <strong>let </strong>cache = {};<br><br>  <strong>return function</strong>(name, stateProperty) {<br>    <strong>if</strong>(name <strong>in </strong>cache) {<br>      <strong>return </strong>cache[name];<br>    } <strong>else </strong>{<br>      <strong>const </strong>cachedProperty = stateProperty.filter(key =&gt; key[keyProp] === name);<br>      cache[name] = cachedProperty;<br>      <strong>return </strong>cachedProperty;<br>    }<br>  }<br>}<br><strong>const </strong>memoizedSelection = memoizeSelection(&#39;location&#39;);<br><strong>export const </strong>selectSchoolsByCountry = (name, stateProperty) =&gt; {<br>  <strong>return </strong>memoizedSelection(name, stateProperty);<br>};</pre><p>Then selectSchoolsByCountry get exported with memoizedSelection. The curried function memoizeSelection that saves the object ‘cache’ gets returned. When selectSchoolsByCountry(‘USA’, state.schools) gets called, the first key in the cache object is USA, and gets saved in selectSchoolsByCountry.</p><p>This function still has a lot of shortcomings. For instance, what happens when the state gets updated, by polling or whatever. The key is cached so selectSchoolsByCountry will still return the same property.</p><p>Luckily <a href="https://github.com/reactjs/reselect">https://github.com/reactjs/reselect</a> does a great job.</p><p>Click on the link below for a fully functioning example.</p><p><strong>Source: </strong><a href="https://github.com/OscarBakker/react_redux_selectors">https://github.com/OscarBakker/react_redux_selectors</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c112facd2eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A React higher order component for mapping state to props and connect]]></title>
            <link>https://medium.com/@bakkeroscar/a-react-higher-order-component-for-mapping-state-to-props-and-connect-11babfcda913?source=rss-19b874ffe6b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/11babfcda913</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Oscar Oscar]]></dc:creator>
            <pubDate>Sat, 14 Apr 2018 15:03:52 GMT</pubDate>
            <atom:updated>2018-04-18T16:10:52.796Z</atom:updated>
            <content:encoded><![CDATA[<p>Using redux now for a few months, I come in situations where I think there is quite a bit of boilerplate for getting a piece of data out of the redux store. You need a typical mapStateToProps function that returns the part of the state that you need and connect it to your component with the ‘react-redux’ connect method.</p><p>When you need a selector <a href="https://github.com/reactjs/reselect">https://github.com/reactjs/reselect</a> for example, you might not want this abstraction. But a lot of component just need an array or an object without modifying them. ConnectProps might be useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*4g70JWQBhF2--o51KZlKDg.png" /></figure><p>You pass in your component as the first argument and an array of state properties and you’re done.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11babfcda913" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>