<?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 Guille Aszyn on Medium]]></title>
        <description><![CDATA[Stories by Guille Aszyn on Medium]]></description>
        <link>https://medium.com/@guilleaszyn?source=rss-ee29b253f1f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iDt2yws6bKeNG_oA.</url>
            <title>Stories by Guille Aszyn on Medium</title>
            <link>https://medium.com/@guilleaszyn?source=rss-ee29b253f1f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:26:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@guilleaszyn/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[Adding Hooks to React Router v4]]></title>
            <link>https://medium.com/@guilleaszyn/adding-hooks-to-react-router-v4-ab23fd945276?source=rss-ee29b253f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab23fd945276</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[component-libraries]]></category>
            <dc:creator><![CDATA[Guille Aszyn]]></dc:creator>
            <pubDate>Fri, 26 Jan 2018 15:38:07 GMT</pubDate>
            <atom:updated>2018-01-26T16:52:22.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_xCMdlVKqxIxPWVkFXVKA.png" /></figure><p>react-route-hook lets you use onEnter, onLeave, and onChange hooks</p><p>TL;DR: If you want to use the library directly you can go to the <a href="http://github.com/guilleasz/RouteHook">github repo</a> and read the documentation. Bellow there is a brief of the motivation for writing this library.</p><p>The new React Router library changed the paradigm completely. Being so used to Static Routing, the adaptation turned out a little rough, but the advantages where quickly appreciated. Declarative routing not only gave us decision freedom but also it makes more sense with the way we are used to create React Components.</p><p>We don’t need to write any configuration outside our app, instead the Routes are just components that are rendered in our UI depending of the location of our URL. And this, they being simple components, brings us back the React philosophy, where we can write, reuse, and compose components that uses routes.</p><p>A really clear example of this can be seen in the <a href="https://reacttraining.com/react-router/web/example/auth-workflow">docs</a> of React-Router where it creates a PrivateRoute, a wrapper which renders aRoute or a Redirect depending if the user is authenticated or not. This example really was the one that made me fall in love with the new paradigm of React Router.</p><p>But there was something that seemed odd to me. Those who come from React-Router v3 were used to have hooks as onEnter onChange and onLeave for, as an example, dispatching actions to our store, or making calls to our API. This hooks were completely erased in the new React Router, and the reasons seemed the right ones.</p><p>This hooks were simply wrappers around existing functionality. They were just a component’s lifecycle hooks replacement. onEnter replaced componentWillMount, onChange was componentWillReceiveProps, and onLeave fulfilled the purpose of componentWillUnmount.</p><p>But this brought a problem to me. My presentational dummy components that were connected to my redux store now needed to be React Classes only for dispatching actions when they were loaded. My stateless functions needed to be turned into classes, that didn’t contain any state, to made use of their lifecycle hooks. This just made my components less re-usable.</p><p>Another solution I came up with, was to write a container for each componente that I needed to dispatch actions. This let me separate the logic from my dummy components. But now I was just creating classes which only used lifecycle hooks, and always rendered only one component. This job was really repetitive.</p><p>So I decided to bring back to life an old React-Router 3 utility. RouteHook is just a wrapper for the lifecycle hooks of a container which is going to execute the functions we pass down to it as props when the route renders the component.</p><p>react-route-hook takes advantage of the new Route composition possibilities for creating a simple component that will let us use hooks in our routes and keep our dummy components as dummies as they should be.</p><h3>Example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/637a6bec4fb5028f79ff9a00a0b354cc/href">https://medium.com/media/637a6bec4fb5028f79ff9a00a0b354cc/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab23fd945276" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>