<?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[hexient-labs - Medium]]></title>
        <description><![CDATA[Tiny thoughts from the team at Hexient Labs - Medium]]></description>
        <link>https://medium.com/hexient-labs?source=rss----8a4f15c9336e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>hexient-labs - Medium</title>
            <link>https://medium.com/hexient-labs?source=rss----8a4f15c9336e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:47:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/hexient-labs" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Better Google Maps + React]]></title>
            <link>https://medium.com/hexient-labs/better-google-maps-react-dddebd367914?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/dddebd367914</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 22:39:24 GMT</pubDate>
            <atom:updated>2018-10-13T22:39:24.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Improving the Google Maps Search developer experience.</p><p>If you’re reading this you’re probably confused/angry/distraught about the lack of resources on integrating a Google Maps Autocomplete or SearchBox into your React app.</p><p>Personally, I had a terrible time writing location-picker components for years- so I finally decided to do something about it. This is a post about my new Google Maps wrapper: <a href="https://www.npmjs.com/package/@loadup/react-google-places-autocomplete">https://www.npmjs.com/package/@loadup/react-google-places-autocomplete</a>.</p><p>In the past, my go-to library for integrating Google Maps was <a href="https://github.com/tomchentw/react-google-maps">https://github.com/tomchentw/react-google-maps</a>. <a href="https://github.com/tomchentw">Tom Chen</a> did a super awesome job writing this library; however, I always found it a little tedious to require recompose and Higher-Order Components just to render a simple SearchBox. I decided I wanted my wrapper library to take a different approach.</p><h3>Project Gooooooooooals</h3><ul><li><strong>Trivial Configuration: </strong>Load Google Maps via the normal &lt;script&gt; tag within our index.html.</li><li><strong>Approachable:</strong> Don’t necessitate use of a Higher-Order Component. Make the library declarative, readable, and approachable for even the most junior devs.</li><li><strong>Configurable: </strong>Allow the developer to dictate what information they want back from Google. We don’t support every single option in the Autocomplete and SearchBox widgets, but enough to be dangerous.</li><li><strong>Not Dreadful:</strong> Normally when using the Google Maps libraries, I find it absolutely painful to parse the address_components array to find the city, state, and zip. We take care of that.</li><li><strong>Cheap:</strong> As of the summer of 2018, Google updated <a href="https://developers.google.com/maps/previous-pricing">the way they price their Maps API calls</a> (making it <strong><em>substantially</em></strong> more expensive). Our library by default integrates the Session Call method, ideally automagically reducing the amount you pay for the service.</li></ul><h3>Usage</h3><p>Here’s the most basic uses of our Autocomplete and SearchBox components.</p><p>For reference, the Autocomplete component maps to the <a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete">Autocomplete Widget</a> and is used for finding addresses like “3310 North Riverside Parkway”. Contrarily, the SearchBox component maps to the <a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete">SearchBox Widget</a> which is used for searching for places like “Pizza in Chicago”.</p><p><em>Installation</em></p><pre>yarn add @loadup/react-google-maps-autocomplete</pre><p><em>Use the </em><a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete"><em>Autocomplete</em></a></p><pre><strong>import</strong> React, { Component } <strong>from</strong> &#39;react&#39;<br><strong>import</strong> { Autocomplete } <strong>from</strong> &#39;@loadup/react-google-places-autocomplete&#39;</pre><pre>class AutocompleteExample extends Component {<br>  render () {<br>    <strong>return</strong> (<br>      &lt;Autocomplete<br>        <strong>fields</strong>={[<br>          &#39;address_components&#39;,<br>          &#39;formatted_address&#39;,<br>          &#39;place_id&#39;<br>        ]}<br>        <strong>id</strong>=&quot;example-autocomplete-id&quot;<br>        <strong>onPlaceChanged</strong>={({ original, parsed }) =&gt; {<br>          <em>// Do whatever you want<br>          // original is the Google Maps PlaceResult Object<br>          // parsed is the parsed version of the address components<br>        </em>}}<br>        <strong>types</strong>={[&#39;address&#39;]}<br>      /&gt;<br>    )<br>  }<br>}</pre><pre><strong>export</strong> default AutocompleteExample</pre><p><em>Use the </em><a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete"><em>SearchBox</em></a></p><pre><strong>import</strong> React, { Component } <strong>from</strong> &#39;react&#39;<br><strong>import</strong> { SearchBox } <strong>from</strong> &#39;@loadup/react-google-places-autocomplete&#39;</pre><pre>class SearchBoxExample extends Component {<br>  render () {<br>    <strong>return</strong> (<br>      &lt;SearchBox<br>        <strong>id</strong>=&quot;example-searchbox-id&quot;<br>        <strong>onPlaceChanged</strong>={({ original, parsed }) =&gt; {<br>          <em>// Do whatever you want<br>          // original is an array of Google Maps PlaceResult Object<br>          // parsed is an array of parsed address components<br>        </em>}}<br>      /&gt;<br>    )<br>  }<br>}</pre><pre><strong>export</strong> default SearchBoxExample</pre><p>Tada! A declarative, reliable, pain-free way to use Google Maps in your React apps!</p><p>This project is sponsored by 🍕 and <a href="https://goloadup.com/">LoadUp Technologies</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dddebd367914" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/better-google-maps-react-dddebd367914">Better Google Maps + React</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQLDataWrapper Component]]></title>
            <link>https://medium.com/hexient-labs/graphqldatawrapper-component-c20337aa3751?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/c20337aa3751</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Wed, 01 Aug 2018 05:38:38 GMT</pubDate>
            <atom:updated>2018-08-02T01:26:46.900Z</atom:updated>
            <content:encoded><![CDATA[<p>Declaratively manage GraphQL data from Apollo Client.</p><p>If you’re a fan of GraphQL, you’ve probably heard of <a href="https://www.apollographql.com/docs/react/">Apollo</a>. The team behind Meteor is building awesome full-stack tooling for the GraphQL community.</p><p>Anyway, in their recent <a href="https://www.apollographql.com/docs/react/react-apollo-migration.html">React Apollo 2.1 release</a> they made a paradigm shift to include declarative data-fetching components that can be used inside a render function, as opposed to just higher-order components that wrap our base components with additional data props.</p><figure><img alt="Image result for react apollo" src="https://cdn-images-1.medium.com/proxy/1*JiTff85gB4lKHtAhykBGKQ.png" /></figure><p>What does this actually mean?</p><p>Well, before the 2.1 release, we had to use Apollo like so:</p><pre>// ExampleComponent.js</pre><pre>import React, { Component } from &#39;react&#39;<br>import { graphql } from &#39;react-graphql&#39;<br>import gql from &#39;graphql-tag&#39;</pre><pre>const QUERY = gql`<br>  query CurrentUser {<br>    currentUser {<br>      id<br>      firstName<br>      lastName<br>      friends {<br>        id<br>        firstName<br>      }<br>    }<br>  }<br>}</pre><pre>const ExampleComponent = ({<br>  data: {<br>    currentUser,<br>    error,<br>    loading<br>  }<br>) =&gt; (<br>  &lt;div&gt;<br>    {/* Do something with the data */}<br>  &lt;/div&gt;<br>)</pre><pre>const withQuery = graphql(QUERY)</pre><pre>export default withQuery(ExampleComponent)</pre><p>HOCs are a great tool; however, this is an opaque implementation that doesn’t take full advantage of React’s component-based architecture.</p><p>The newer client library introduces a declarative Query component which fully utilizes React’s component system and the hot <a href="https://reactjs.org/docs/render-props.html">render-prop pattern</a>.</p><pre>// DeclarativeExampleComponent.js</pre><pre>import React, { Component } from &#39;react&#39;<br>import { Query } from &#39;react-graphql&#39;<br>import gql from &#39;graphql-tag&#39;</pre><pre>const QUERY = gql`<br>  query CurrentUser {<br>    currentUser {<br>      id<br>      firstName<br>      lastName<br>      friends {<br>        id<br>        firstName<br>      }<br>    }<br>  }<br>}</pre><pre>const DeclarativeExampleComponent = (props) =&gt; (<br>  &lt;div&gt;<br>    &lt;Query query={QUERY}&gt;<br>      {({ data, error, loading }) =&gt; {<br>        // Do something with the data<br>      }}<br>    &lt;/Query&gt;<br>  &lt;/div&gt;<br>)</pre><pre>export default ExampleComponent</pre><p>Amazing boost in clarity, right? This snippet looks a lot more familiar and approachable to React and GraphQL newbies and reduces cognitive load on the developer by sticking solely to React components. Using the render-prop pattern, the Query component takes a function as it’s children and that function returns some JSX.</p><p>Here lies the issue. A naive approach to using the Query component would lead to a lot of code duplication.</p><pre>&lt;Query query={QUERY}&gt;<br>  {({ data, error, loading }) =&gt; {<br>    if (loading) return &lt;h1&gt;Loading...&lt;/h1&gt;<br>    if (error) return &lt;h1&gt;There was an error!&lt;/h1&gt;<br>    <br>    return &lt;UserProfile user={data.currentUser} /&gt;<br>  }}<br>&lt;/Query&gt;</pre><p>Every time we use the Query component to run a GraphQL query, we’d have repeated conditional, imperative logic for checking loading and error conditions.</p><h3>GraphQLDataWrapper</h3><p>At <a href="https://hexientlabs.com/">Hex Labs</a>, we hated this problem so we developed a custom component called our GraphQLDataWrapper. It’s a really simple, declarative interface that encapsulates the logic above. Here’s a snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59b864a7b9862a5a55956cacc0db5aaa/href">https://medium.com/media/59b864a7b9862a5a55956cacc0db5aaa/href</a></iframe><p>This component abstracts error, loading, and success state from any given GraphQL Query, conditionally rendering default Error and Loading components that can be overridden. We can use the component like so:</p><pre>&lt;Query query={QUERY}&gt;<br>  {rp =&gt; (<br>    &lt;GraphQLDataWrapper<br>      {...rp}<br>      renderData={({ data, ...rest }) =&gt; {<br>        // Do something with the data<br>      )}<br>    &lt;/GraphQLDataWrapper&gt;<br>  )}<br>&lt;/Query&gt;</pre><p>Now, instead of individually dealing with errors, and loading states, it’s all taken care of! Woo! And in case you’re curious, the rest key passed to the renderData prop will contain additional render-props from the Query component such as refetch, fetchMore, and variables. You can find the whole list <a href="https://www.apollographql.com/docs/react/api/react-apollo.html#query-render-prop">here</a>.</p><p>Anyway, I know that’s a lot to take in, but I hope it hopes someone out there DRY up their code :)</p><p><em>Heads up, I’m building a really neat abstraction layer on top of any database that automatically creates REST and GraphQL APIs for you. If you want early access, </em><a href="https://goo.gl/forms/1ac7ktX8FdySPdD03"><em>fill out our survey here</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c20337aa3751" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/graphqldatawrapper-component-c20337aa3751">GraphQLDataWrapper Component</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sweet HOCs: withHoverState]]></title>
            <link>https://medium.com/hexient-labs/sweet-hocs-withhoverstate-2cedf88600b5?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/2cedf88600b5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Fri, 20 Jul 2018 01:32:04 GMT</pubDate>
            <atom:updated>2018-09-24T21:13:38.678Z</atom:updated>
            <content:encoded><![CDATA[<p>A reusable way to write hover effects in React.</p><p>If you’re a UX nut, you’ve probably implemented some sort of “hover” effect. If you’re a React developer, you’ve probably implemented hover effects using the onMouseEnter and onMouseLeave events on a DOM element.</p><p>Unfortunately, managing this state over and over can be painful, and add bloat to your React application. What if there was a way to automagically know whether our component is being hovered?</p><h3>Enter <a href="https://github.com/renatorib/react-powerplug">React Powerplug</a></h3><p>React Powerplug is a utility library full of components that use <a href="https://reactjs.org/docs/render-props.html">render props</a> to help you write fully controlled components without managing state yourself. This is immensely helpful when writing pure functional components and composing additional state, as opposed writing class-based components and managing this.state yourself.</p><p>First, let’s look at how we normally have to manage hover state on a div.</p><pre>// BasicHoverExample.js</pre><pre>import React, { Component } from &#39;react&#39;</pre><pre>class BasicHoverExample extends Component {<br>  state = {<br>    hovered: false<br>  }</pre><pre>  this.updateHoverState = nextHoverState =&gt; <br>    this.setState({ hover: nextHoverState })</pre><pre>  render() {<br>    return (<br>      &lt;div<br>        onMouseEnter={() =&gt; this.updateHoverState(true)}<br>        onMouseLeave={() =&gt; this.updateHoverState(false)}<br>        style={{<br>          backgroundColor: this.state.hovered ? &#39;red&#39; : &#39;blue&#39;<br>        }}<br>      &gt;<br>        {/* more content */}<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><pre>export default BasicHoverExample</pre><p>Now this is kind of a contrived example; regardless, managing hover state manually with DOM events is <em>painful</em>.</p><p>Now, let’s look at writing a basic higher-order component to manage this same hover state.</p><pre>// withHoverBasicHOC.js</pre><pre>import React, { Component } from &#39;react&#39;</pre><pre>const withHoverBasicHOC = BaseComponent =&gt;<br>  class Wrapper extends Component {<br>    state = {<br>      hovered: false<br>    }</pre><pre>    this.updateHoverState = nextHoverState =&gt;<br>      this.setState({ hovered: nextHoverState })</pre><pre>    render() {<br>      return (<br>        &lt;div<br>          onMouseEnter={() =&gt; this.updateHoverState(true)}<br>          onMouseLeave={() =&gt; this.updateHoverState(false)}<br>        &gt;<br>          &lt;BaseComponent<br>            {...this.props}<br>            hovered={this.state.hovered}<br>          /&gt;<br>        &lt;/div&gt;<br>      )<br>    }<br>  }</pre><pre>export default withHoverBasicHOC</pre><p>As you can see, withHoverBasicHOC manages the hovered state itself and just applies that state as a prop to the BaseComponent. We can use that HOC like so:</p><pre>// ComposedBasicHoverExample.js</pre><pre>import React from &#39;react&#39;<br>import withHoverBasicHOC from &#39;./withHoverBasicHOC&#39;</pre><pre>const ComposedBasicHoverExample = props =&gt; (<br>  &lt;div<br>    style={{<br>      backgroundColor: props.hovered ? &#39;red&#39; : &#39;blue&#39;<br>    }}<br>  /&gt;<br>)</pre><pre>export default withHoverBasicHOC(ComposedBasicHoverExample)</pre><p>Wow! Awesome right? What a reduction in code and state management in the component where we want a hover state!</p><p>Last but not least… let’s see how react-powerplug can make our HOC even simpler with their Hover component that automatically manages events for us!</p><pre>// withHoverViaPowerplug.js</pre><pre>import React from &#39;react&#39;<br>import { Hover as H } from &#39;react-powerplug&#39;</pre><pre>export default Base =&gt; p =&gt; &lt;H&gt;{rp =&gt; &lt;Base {...p} {...rp} /&gt;}&lt;/H&gt;</pre><p>Wut. With the Hover components, we don’t have to manage any state ourselves which allows us to write our HOC as a pure functional component! To explain the one-liner above, we’re exporting a function that takes a component ( Base ) and the props applied to Base ( p ) and implicitly returns a Hover component, H which uses render props that we apply to Base.</p><p>And from there, our integration into our affected component looks like:</p><pre>// HoverExampleViaPowerplug.js</pre><pre>import React from &#39;react&#39;<br>import withHoverViaPowerplug from &#39;./withHoverViaPowerplug&#39;</pre><pre>const HoverExampleViaPowerplug = props =&gt; (<br>  &lt;div<br>    {...props.bind}<br>    style={{<br>      backgroundColor: props.hovered ? &#39;red&#39; : &#39;blue&#39;<br>    }}<br>  /&gt;<br>)</pre><pre>export default withHoverViaPowerPlug(HoverExampleViaPowerplug)</pre><p>Zoinks! And just like that, we have a functional one-liner to apply a hover state onto any component!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cedf88600b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/sweet-hocs-withhoverstate-2cedf88600b5">Sweet HOCs: withHoverState</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple GraphQL Enums]]></title>
            <link>https://medium.com/hexient-labs/simple-graphql-enums-245ef83a509?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/245ef83a509</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Thu, 12 Jul 2018 06:41:07 GMT</pubDate>
            <atom:updated>2018-07-12T06:41:06.920Z</atom:updated>
            <content:encoded><![CDATA[<p>A simple way to use constants in your GraphQL and Database Schemas.</p><p>Over the past year, <a href="https://hexientlabs.com/">Hex Labs</a> has gone all in on <a href="https://graphql.org/">GraphQL</a>. We love the strongly-typed guarantees, introspection capabilities, and granular analytics it enables.</p><p>One thing were always struggled with; however, was how to organize our enums or known constant values efficiently for use across our application. This includes usage in our various services, GraphQL Schemas, and database validation logic.</p><p>We’ve recently come up with an organization that we think is pretty good. Let’s start with the example of enumerating <a href="https://stripe.com/">Stripe</a> Plans, which represent the various free and paid plans a user can be subscribed to on our platform. The possible values of the plans are: free , hobby , growth , and enterprise .</p><h3>Project Structure &amp; Defining Constants</h3><p>Let’s image out file structure looks like this:</p><pre>// Application File Structure</pre><pre>/src<br>|    /Constants<br>|--    index.js<br>|--    index.test.js<br>|----    /StripePlans<br>|------    index.js<br>|------    index.test.js<br>|    /Enums<br>|--    index.js<br>|--    typeDefs.js<br>|--    typeDefs.test.js<br>|--    resolvers.js<br>|--    resolvers.test.js<br>|    ...rest of your GraphQL Schema, Data Services, etc</pre><p>Let’s start with the file StripePlans/index.js. This file will export key-value pairs that represent the Stripe plans.</p><pre>// StripePlans/index.js</pre><pre>module.exports = {<br>  FREE: &#39;free&#39;,<br>  HOBBY: &#39;hobby&#39;,<br>  GROWTH: &#39;growth&#39;,<br>  ENTERPRISE: &#39;enterprise&#39;<br>}</pre><p>This file is fairly simple and allows you to reference the actual plans, the values like so: StripePlans.HOBBY.</p><p>Now, let’s take a quick look at Constants/index.js. This file will collect and export all sub-constants in the application.</p><pre>// Constants/index.js</pre><pre>const StripePlans = require(&#39;./StripePlans&#39;)</pre><pre>module.exports = {<br>  StripePlans,<br>}</pre><p>Fairly straightforward so far, yes?</p><h3>GraphQL Enums</h3><p><a href="https://graphql.org/learn/schema/">GraphQL enums</a> let consumers of your API query with strongly typed constants instead of just plain strings.</p><p>Let’s take a look at our typeDefs and resolvers for these enums.</p><pre>// Enums/typeDefs.js</pre><pre>import { gql } from &#39;apollo-server&#39;<br>import Constants from &#39;../Constants&#39;</pre><pre>module.exports = gql`<br>  enum StripePlans {<br>    ${Object.keys(Constants.StripePlans}<br>`</pre><p>Kaboom! How easy is that? Just map over the keys of the the StripePlans from constants, and you have immediately declared FREE , HOBBY , GROWTH , and ENTERPRISE as enum values.</p><p>Now, that’s awesome, but it doesn’t map to the actual values of those keys…yet. To do that, let’s hop into our resolvers file.</p><pre>// Enums/resolvers.js</pre><pre>import Constants from &#39;../Constants&#39;</pre><pre>module.exports = Constants</pre><p>Wut. Awesome, right? Because of our clear and consistent naming conventions, we’re actually able to just use our Constants and the resolvers for our enums! Just plug your typeDefs and resolvers into you GraphQL schema and you’re good to go!</p><p>Now, when someone queries with the enum type HOBBY as a param, you’ll actually receive the value of that enum ( hobby) in your resolver! This is awesome because you no longer have to manually map the enum to the value using the Constants file- it’s a win-win-win.</p><p>Happy coding!</p><p><em>Heads up, I’m building a really neat abstraction layer on top of any database that automatically creates REST and GraphQL APIs for you. If you want early access, </em><a href="https://goo.gl/forms/1ac7ktX8FdySPdD03"><em>fill out our survey here</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=245ef83a509" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/simple-graphql-enums-245ef83a509">Simple GraphQL Enums</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sweet HOCs: withBoxShadow]]></title>
            <link>https://medium.com/hexient-labs/sweet-hocs-withboxshadow-6ad6633414c7?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6ad6633414c7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Mon, 07 May 2018 02:49:19 GMT</pubDate>
            <atom:updated>2018-05-07T02:49:19.415Z</atom:updated>
            <content:encoded><![CDATA[<p>A wildly simple way to visually enhance your components.</p><p>In all of our apps at Hexient Labs, we try hard to ensure visual consistency among each component library. Managing this on a per-component basis can become very difficult if you’re applying classNames on the web, or inline styles in React Native.</p><p>We’re huge fans of functional programming, and as such, love managing visual consistency through composition. One of the easiest ways to grasp this concept is with a Higher-Order Component we use called withBoxShadow. This component can be applied to any class or functional component and wraps it in a div or View with a box shadow applied to it.</p><p>Here it is:</p><pre>// withBoxShadow.js</pre><pre>import React from &#39;react&#39;<br>import { View } from &#39;react-native&#39;<br>import Colors from &#39;./constants/Colors&#39;</pre><pre>const withShadow = BaseComponent =&gt; props =&gt; (<br>  &lt;View<br>    style={{<br>      shadowColor: Colors.shadow,<br>      shadowOffset: { width: 2, height: 4 },<br>      shadowOpacity: 0.1<br>    }}<br>  &gt;<br>    &lt;BaseComponent {...props} /&gt;<br>  &lt;/View&gt;<br>)</pre><pre>export default withShadow</pre><p>And it can be used just like this:</p><pre>// NotificationItem.js</pre><pre>import React from &#39;react&#39;<br>import { Text, View } from &#39;react-native&#39;<br>import withBoxShadow from &#39;./withBoxShadow&#39;</pre><pre>const NotificationItem = ({ message }) =&gt; &lt;Text&gt;{message}&lt;/Text&gt;</pre><pre>export default withBoxShadow(NotificationItem)</pre><p>…and just like that, we transform our boring text items to have a beautiful box shadow 😃.</p><p>This is a bit of a contrived example; however, I hope you can see the potential to manage visual consistency and general styles via composition.</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad6633414c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/sweet-hocs-withboxshadow-6ad6633414c7">Sweet HOCs: withBoxShadow</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sweet HOCs: withEnterTransition]]></title>
            <link>https://medium.com/hexient-labs/sweet-hocs-withentertransition-88216e741128?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/88216e741128</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 14:56:01 GMT</pubDate>
            <atom:updated>2018-04-24T14:56:01.099Z</atom:updated>
            <content:encoded><![CDATA[<p>A super simple Higher-Order Component to add a mounting transition to any component.</p><p>If you’ve ever wanted to create a cute mounting animation to delight your users, we’ve got a great solution for you. Our solution today will use <a href="https://medium.com/@joomiguelcunha/amazing-react-animation-with-react-pose-3b67d9eb6e07">React-Pose by Popmotion</a> in conjunction with <a href="https://github.com/acdlite/recompose">Recompose</a> and <a href="http://ramdajs.com/">Ramda</a> to create a HOC that implements an animation.</p><p>Let’s dive in!</p><pre>// withEnterTransition.js</pre><pre>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { omit } from &#39;ramda&#39;<br>import { compose, lifecycle, setPropTypes, withStateHandlers } from &#39;recompose&#39;<br>import posed from &#39;react-pose&#39;</pre><pre>// Declare separate animation states<br>const poseProps = {<br>  hidden: {<br>    y: 10,<br>    opacity: 0,<br>  },<br>  visible: {<br>    y: 0,<br>    opacity: 1,<br>  }<br>}</pre><pre>// Create animated wrapper<br>const PosedContainer = posed.div(poseProps)</pre><pre>// Component with Animation<br>const withEnterTransition = BaseComponent =&gt; props =&gt; {<br>  const baseProps = omit([&#39;delay&#39;, &#39;poseState&#39;], props)<br>  return (<br>    &lt;PosedContainer pose={props.poseState}&gt;<br>      &lt;BaseComponent {...baseProps} /&gt;<br>    &lt;/PosedContainer&gt;<br>  )<br>}</pre><pre>// Create props and prop change handlers to manage Pose State<br>const withState = withStateHandlers(<br>  ({ poseState = &#39;hidden&#39; }) =&gt; ({<br>    poseState,<br>  }),<br>  {<br>    updatePose: ({ poseState }) =&gt; (nextPoseState) =&gt; ({<br>      poseState: nextPoseState<br>    }),<br>  }<br>)</pre><pre>// When the component mounts, after a timeout, update Pose state<br>const withLifecycle = lifecycle({<br>  componentDidMount() {<br>    setTimeout(() =&gt; {<br>      this.props.updatePose(&#39;visible&#39;)<br>    }, this.props.delay || 500)<br>  }<br>})</pre><pre>// Declare PropTypes<br>const withPropTypes = setPropTypes({<br>  delay: PropTypes.number,<br>})</pre><pre>export default compose(<br>  withState,<br>  withLifecycle,<br>  withPropTypes,<br>  withEnterTransition<br>)</pre><p>Okay… I know that was intense. But if we break it down piece by piece, it starts to make sense.</p><p><strong>First</strong>, to understand this example, you fundamentally have to understand how the <a href="https://medium.com/@joomiguelcunha/amazing-react-animation-with-react-pose-3b67d9eb6e07">React-Pose by Popmotion</a> library works. All we have to do to trigger an animation is change the pose props on the PosedContainer to one of the designated states, and a transition will fire.</p><p>In this case, we change the opacity and y-position from (0, 10) to (1, 0), respectively.</p><p><strong>Second</strong>, we create our own composed functionality called withState that creates some local state and a local state change handler for updating the poseState of a given component. We will soon apply this component to the PoseContainer and lifecycle hooks.</p><p><strong>Third</strong>, we create our own lifecycle hooks and use the componentDidMount lifecycle method to trigger an animation after a specific timeout (the delay prop).</p><p><strong>Fourth</strong>, we enhance our base component with the necessary delay PropType.</p><p><strong>Lastly</strong>, we compose all our HOCs together to apply them to a base component!</p><h3>Using Our HOC</h3><p>It’s actually super straightforward.</p><pre>// Example.js</pre><pre>import React from &#39;react&#39;<br>import { compose } from &#39;recompose&#39;<br>import withEnterTransition from &#39;./withEnterTransition&#39;</pre><pre>const Example = props =&gt; &lt;h1&gt;{props.title}&lt;/h1&gt;</pre><pre>export default compose(withEnterTransition)(Example)</pre><p>Kaboom!</p><p>Now when we use the &lt;Example delay={1000} title=&quot;Hello, world!&quot; /&gt; component in the rest of our code, the component will fade in and up after a delay of 1s.</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88216e741128" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/sweet-hocs-withentertransition-88216e741128">Sweet HOCs: withEnterTransition</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux, Ramda, Reselect, Recompose]]></title>
            <link>https://medium.com/hexient-labs/redux-ramda-reselect-recompose-41171dcf63fd?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/41171dcf63fd</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 21:59:54 GMT</pubDate>
            <atom:updated>2018-04-23T17:03:23.584Z</atom:updated>
            <content:encoded><![CDATA[<p>A VERY functional approach to React token-based authentication.</p><p>Buckle in folks cause this is going to be a long one.</p><p>This post covers the intersection of authentication, <a href="https://redux.js.org/">Redux</a>, <a href="http://ramdajs.com/docs/">Ramda</a>, <a href="https://github.com/reactjs/reselect">Reselect</a>, and <a href="https://github.com/acdlite/recompose">Recompose</a>, all in the context of protecting our authenticated routes in a React app. We won’t be diving too deep into any library in particular, but we’ll discuss how to use them in tandem to run the world.</p><p>First let’s do a brief primer on each of our angles of attack.</p><h3>Authentication</h3><p>This will NOT be the most secure web app in the world. We will be flying by the large assumption that if we are currently storing a token in Redux, we are authenticated. If token is null, we are unauthenticated.</p><h3><a href="https://redux.js.org/">Redux</a></h3><p>What is Redux? This is far too deep a rabbit hole to dig into right now; however, let’s rely on the fact that Redux is where we store all the state (data) for our React app.</p><p>Components can read from and write to our Redux store (imagine a big, shared JavaScript object) and this is where we will store our token. Our Redux store will be shaped like this:</p><pre>// Describing the type of our Redux store using `flow`</pre><pre>type ReduxStoreType = {<br>  auth: {<br>    token: ?string<br>  }<br>}</pre><p>For demonstration purposes, our Redux store will have one branch (auth) which has a token that can be a string or null.</p><h3><a href="http://ramdajs.com/">Ramda</a></h3><p>If you’re familiar with <a href="http://underscorejs.org/">Underscore.</a>js or <a href="https://lodash.com/">Lodash</a>, you’ll love Ramda even more. Ramda applies immutability and functional approaches to their implementation of these generic “toolbelt” functions.</p><p>One of the great advantages of Ramda is that their functions are automatically <a href="https://www.sitepoint.com/currying-in-functional-javascript/">curried</a>. Currying provides huge benefits in functional programming which relies heavily on the principle of partial application. Here’s an example without going too much into theory:</p><pre>// Ramda example</pre><pre>const R = require(&#39;ramda&#39;)</pre><pre>const DATA = [1, 2, 3, 4, 5]</pre><pre>// Full application<br>const uncurriedExample = R.indexOf(3, DATA) // 2</pre><pre>// Partial application<br>const curriedExample = R.indexOf(3)(Data) // 2</pre><pre>// Or if you want to create a function beforehand</pre><pre>// Create function to be used later<br>const indexOf3 = R.indexOf(3)</pre><pre>const anotherCurriedExample = indexOf3(DATA) // 2</pre><p>It may not be obvious, especially if you come from an OOP background, but currying lays the groundwork for configurable factory functions and other functional programming constructs.</p><h3><a href="https://github.com/reactjs/reselect">Reselect</a></h3><p>Reselect is a library for computing derived data with <a href="https://medium.freecodecamp.org/understanding-memoize-in-javascript-51d07d19430e">memoized</a> selectors.</p><p>What 🤔?</p><p>Skipping over memoization, Reselect pairs excellently with Redux to help you grab the exact data you want out of a branch of your redux store. This concept can be hard to understand, specifically if you haven’t dealt with the problem is solves. Here’s an example:</p><pre>// Example Redux Store using `flow` type</pre><pre>type ReduxStoreType = {<br>  friends: {<br>    activeIndex: number,<br>    data: Array&lt;Friend&gt;,<br>  }<br>}</pre><p>Now, if you just wanted to see your activeFriend = friends.data[activeIndex] many developers would access this data directly inside of a render function. This couples your component directly to the structure of your data which isn’t a maintainable practice in large applications and minimizes code reuse.</p><p>Here’s an example of this BAD practice:</p><pre>// BAD EXAMPLE - GreatFriend.js</pre><pre>import React, { Component } from &#39;react&#39;<br>import { connect } from &#39;react-redux&#39;</pre><pre>class GreatFriend extends Component {<br>  render() {<br>    const { activeIndex, data } = this.props<br>    const activeFriend = data[activeFriend]</pre><pre>    return &lt;h1&gt;{activeFriend.firstName}&lt;/h1&gt;<br>  }<br>}</pre><pre>const mapStateToProps = state =&gt; ({<br>  friends: state.friends,<br>})</pre><pre>export default connect(mapStateToProps)(GreatFriend)</pre><p>This is bad for a couple reasons. First, like we mentioned above, GreatFriend is directly responsible for finding the activeFriend. We’re directly exposing data-structure details to this component, which is not it’s direct responsibility.</p><p>Another issue here is that whenever anything inside the friends key of the Redux store changes, this component will re-render, leading to poor performance.</p><p>Now, here’s an example of how we can use Reselect to create a memoized selector to grab just our activeFriend eliminating re-renders and decoupling our component and data:</p><pre>// GOOD EXAMPLE - GreatFriend.js</pre><pre>import React from &#39;react&#39;<br>import { connect } from &#39;react-redux&#39;<br>import { createSelector } from &#39;reselect&#39;</pre><pre>// Selectors<br>const friends = state =&gt; state.friends</pre><pre>// Base selector to get the activeIndex from friends<br>const getActiveIndex = createSelector(<br>  friends,<br>  _ =&gt; _.activeIndex<br>)</pre><pre>// Base selector to get the data from friends<br>const getData = createSelector(<br>  friends,<br>  _ =&gt; _.data<br>)</pre><pre>// Compose base selectors to get activeFriend<br>const getActiveFriend = createSelector(<br>  [getData, getActiveIndex],<br>  (data, activeIndex) =&gt; data[activeIndex]<br>)</pre><pre>// Component<br>const GreatFriend = props =&gt; &lt;h1&gt;{props.activeFriend.firstName}&lt;/h1&gt;</pre><pre>const withRedux = connect(state =&gt; ({<br>  activeFriend: getActiveFriend(state)<br>}))</pre><pre>export default withRedux(GreatFriend)</pre><p>This may look convoluted now, but with a couple selector factory functions and some code organization, we achieve a very clean architecture that separates Redux, data access, and rendering.</p><h3><a href="https://github.com/acdlite/recompose">Recompose</a></h3><p>Recompose is another functional “toolbelt” library that abstracts common React functionality implementation details into pre-packaged <a href="https://reactjs.org/docs/higher-order-components.html">higher-order components</a> (HOCs).</p><p>HOCs are a very interesting and powerful pattern to enhance dumb components with new, reusable, composable functionality. Recompose exposes some simple and some complex HOCs for developers.</p><p>Here’s a quick example of how we can move in-component PropTypes declarations from within a component to an enhanced HOC.</p><pre>// In-component PropTypes</pre><pre>import React, { Component } from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;</pre><pre>class Example extends Component {<br>  static propTypes = {<br>    name: PropTypes.string.isRequired,<br>  }</pre><pre>  render() {<br>    return &lt;h1&gt;{this.props.name}&lt;/h1&gt;<br>  }<br>}</pre><p>Versus, the functional approach enabled by Recompose:</p><pre>// Enhancer-based PropTypes</pre><pre>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { compose, setPropTypes } from &#39;recompose&#39;</pre><pre>const Example = props =&gt; &lt;h1&gt;{this.props.name}&lt;/h1&gt;</pre><pre>// Enhancers<br>const withPropTypes = setPropTypes({<br>  name: PropTypes.name.isRequired,<br>})</pre><pre>export default compose(withPropTypes)(Example)</pre><p>In the second example here, we’re able to write a dumb functional component (not class-based) and compose new functionality onto it.</p><p>This is a VERY simple, contrived example; however, hopefully it conveys the point. We’ll dive a little deeper in a sec.</p><h4>At this point, we’ve covered core concepts with examples of the libraries we’ll be using to create a HOC that automatically protects our routes. Now onto our example.</h4><h3>Step 1: Writing our Redux Reducer + Selectors</h3><p>Redux Reducers are how we declare the data stored in Redux.</p><p>For this contrived example, our Redux store will look exactly like this:</p><pre>// Describing the type of our Redux store using `flow`</pre><pre>type ReduxStoreType = {<br>  auth: {<br>    token: ?string<br>  }<br>}</pre><p>At <a href="https://hexientlabs.com/">Hexient Labs</a>, we like to colocate our Redux actions, reducers, and selectors for a given feature in the same file due to natural cohesiveness and to avoid file explosions.</p><pre>// auth.js</pre><pre>import { createSelector } from &#39;reselect&#39;<br>import { path } from &#39;ramda&#39;</pre><pre>// Action types<br>export const ACTIONS = {<br>  RESET: &#39;application/auth/RESET&#39;,   // reset the auth token<br>  SET: &#39;application/auth/SET&#39;,       // set the auth token<br>}</pre><pre>// Initial state<br>export const initialState = {<br>  token: null,<br>}</pre><pre>// Reducer<br>export default (reduxState = initialState, action) =&gt; {<br>  const { payload, type } = action<br>  switch (type) {<br>    case ACTIONS.RESET:<br>      return initialState<br>    case ACTIONS.SET:<br>      return { token: payload.token }<br>    default:<br>      return reduxState<br>  }<br>}</pre><pre>/**<br> * Selectors<br> *<br> * This looks very different than the selectors we wrote above.<br> * This is because we&#39;re taking advantage of Ramda&#39;s automatic<br> *   curried functions. The `state` param is applied automatically<br> *   to the `auth` function.<br> *<br> * You could write the exact same thing like this:<br> * const auth = state =&gt; path([&#39;auth&#39;], state)<br> *<br> */<br>const auth = path([&#39;auth&#39;])</pre><pre>/**<br> * We&#39;re using the same auto-currying principle here<br> *<br> */<br>const getAuthToken = createSelector(<br>  auth,<br>  path[&#39;token&#39;],<br>)</pre><pre>export const SELECTORS = {<br>  getAuthToken,<br>}</pre><p>Super clean, right? Ramda auto-currying ability continues to blow me away in how simple makes the rest of our data-access layer.</p><h3>Step 2: Writing our Protection HOC</h3><p>We’ll be using Recompose to write our own custom HOC we can use to enhance and automatically protect our Authenticated routes.</p><pre>// protect.js</pre><pre>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { Redirect } from &#39;react-router-dom&#39;<br>import { connect } from &#39;react-redux&#39;<br>import {<br>  branch,<br>  compose,<br>  renderComponent,<br>  setPropTypes,<br>} from &#39;recompose&#39;<br>import { SELECTORS } from &#39;./auth&#39;</pre><pre>/**<br> * Protect is a HOC<br> * It enhances Base<br> * And spreads enhanced props onto Base<br> *<br> */<br>const protect = Base =&gt; props =&gt; &lt;BaseComponent {...props} /&gt;</pre><pre>// Enhancers</pre><pre>/**<br> * Enhance the Base component with PropTypes<br> *<br> */<br>const withPropTypes = setPropTypes({<br>  token: PropTypes.string,<br>})</pre><pre>/**<br> * Use the branch HOC from Recompose<br> * If there is no token on the component&#39;s props,<br> *  Redirect to /login route,<br> *  Otherwise, show the Base component<br> *<br> */<br>const withRedirect = branch(<br>  ownProps =&gt; !ownProps.token,<br>  renderComponent(() =&gt; &lt;Redirect to=&quot;/login&quot; /&gt;)<br>)</pre><pre>/**<br> * Use the connect HOC to connect the component to Redux<br> * Use the selector to get just the necessary token from Redux<br> *<br> */<br>const withToken = connect(state =&gt; ({<br>  token: SELECTORS.getAuthToken(state),<br>}))</pre><pre>/**<br> * Compose the HOCs together to enhance the Protected Base<br> *<br> */<br>export default compose(<br>  withToken,<br>  withRedirect,<br>  withPropTypes,<br>  protect<br>)</pre><p>Wowza. That was a big one, but in modular fashion we’re able to simply compose functionality together to enhance and protect any arbitrary component. With this protect HOC, we’re able to say:</p><p>If there&#39;s not a token in Redux, redirect to the /login route.</p><p>KABOOM! Now, the final step.</p><h3>Step 3: Protect our Authenticated Routes</h3><p>Imagine the following scenario, when a user lands on our app, they start at the /login page. Then once they authenticate, they are redirected to the /app page which can render any number of routes internal to the application.</p><p>At the top level of our app, we might have a Routes.js file:</p><pre>// Routes.js</pre><pre>import React from &#39;react&#39;<br>import { Route, Router, Switch } from &#39;react-router-dom&#39;<br>import AuthenticatedRoutes from &#39;./AuthenticatedRoutes&#39;<br>import Login from &#39;./Login&#39;<br>import protect from &#39;./protect&#39;</pre><pre>const Routes = () =&gt; (<br>  &lt;Router&gt;<br>    &lt;Switch&gt;<br>      &lt;Route path=&quot;/app&quot; component={protect(AuthenticatedRoutes)} /&gt;<br>      &lt;Route component={Login} /&gt;<br>    &lt;/Switch&gt;<br>  &lt;/Router&gt;<br>)</pre><pre>export default Routes</pre><p>And with that little piece of magic, any user who tries to hit an authenticated route like /profile /friends /feed will automatically be checked for authentication and redirected to the Login page if necessary.</p><p>I know this was a long one, but we just covered a lot of information: 4 excellent functional libraries, and a traceable, debuggable authentication mechanism. Good luck and hit up the comments if you have questions!</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41171dcf63fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/redux-ramda-reselect-recompose-41171dcf63fd">Redux, Ramda, Reselect, Recompose</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mind-blowingly Easy React Animations]]></title>
            <link>https://medium.com/hexient-labs/mind-blowingly-easy-react-animations-41147faad85?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/41147faad85</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 23:55:50 GMT</pubDate>
            <atom:updated>2018-04-04T23:57:41.595Z</atom:updated>
            <content:encoded><![CDATA[<p>MIND FREAKIN’ BLOWN</p><h4>A Journey into Animations</h4><p>At <a href="https://hexientlabs.com/">Hexient Labs</a>, we’ve been writing React and <a href="https://facebook.github.io/react-native/">React Native</a> apps for a couple years. In all this time, we’ve been searching for the “killer” solution to animations. Well friends, the time has come.</p><h4>Pose by Popmotion</h4><p>If you like playful web animations, you’ve probably heard of <a href="https://popmotion.io/">Popmotion</a>. Just last week I stumbled upon another project by Popmotion named <a href="https://popmotion.io/pose/learn/install/#install-react-pose">Pose</a>.</p><p>Pose gives developers access to the exact same declarative motion API as Popmotion, in the context of React.</p><h4>An Example</h4><pre>// AnimatedBoxes.js<br>import React, { Component, Fragment } from &#39;react&#39;<br>import posed from &#39;react-pose&#39;</pre><pre>// Create a `Box` component with different animated states<br>// The states are `active` and `inactive` with different style props<br>// Note: We only determine the different states, not easings<br>// Note: Pose comes with sensible, playful defaults for animations<br>const Box = posed.div({<br>  active: {<br>    opacity: 1,<br>    scale: 1.1,<br>    y: -8,<br>  },<br>  inactive: {<br>    opacity: 0.8,<br>    scale: 1,<br>    y: 0<br>  },<br>})</pre><pre>// Export the component<br>export default class AnimatedBoxes extends Component {<br>  this.state = { activeBox: null }</pre><pre>  _activate = activeBox =&gt; this.setState({ activeBox })</pre><pre>  _deactivate = () =&gt; this.setState({ activeState: null })</pre><pre>  render() {<br>    const { activeBox } = this.state</pre><pre>    return (<br>      &lt;Fragment&gt;<br>        &lt;Box<br>          pose={activeBox === 0 ? &#39;active&#39; : &#39;inactive&#39;}<br>          onMouseEnter={() =&gt; this._activate(0)}<br>          onMouseLeave={this._deactivate}<br>        /&gt;<br>        &lt;Box<br>          pose={activeBox === 1 ? &#39;active&#39; : &#39;inactive&#39;}<br>          onMouseEnter={() =&gt; this._activate(1)}<br>          onMouseLeave={this._deactivate}<br>        /&gt;<br>      &lt;/Fragment&gt;<br>    )<br>  }<br>}</pre><p>You can see in the example above how seamlessly Pose fits into the React declarative paradigm.</p><p>Now, this may not look too impressive, but to us, the magic is the in the sensible, playful default easings and springs that Pose uses. You can interact with the beautiful result of our minimalist code below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmmasia%2Fembed%2Fpreview%2FdmqVBG%3Fheight%3D600%26slug-hash%3DdmqVBG%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fmmasia%2Fpen%2FdmqVBG&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F1888176.dmqVBG.small.4bbfd1f0-a1aa-4ab6-9312-9af0b3eabed4.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/43d6ea76542287d8478905efd65b07fa/href">https://medium.com/media/43d6ea76542287d8478905efd65b07fa/href</a></iframe><p>It really is 😍 🔥 🌮. You can find more docs on Pose and creating beautiful, staggered animations in the <a href="https://popmotion.io/pose/api/posed/">API Documentation</a>.</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41147faad85" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/mind-blowingly-easy-react-animations-41147faad85">Mind-blowingly Easy React Animations</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apollo Provider HOC]]></title>
            <link>https://medium.com/hexient-labs/apollo-provider-hoc-70e8e4dbcff3?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/70e8e4dbcff3</guid>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[recompose]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 01:54:51 GMT</pubDate>
            <atom:updated>2018-03-19T01:54:51.248Z</atom:updated>
            <content:encoded><![CDATA[<p>A one-liner for incorporating the Apollo Client.</p><h3>Using Apollo</h3><p>If you write React and want to use GraphQL, you’ve probably heard of the awesome <a href="https://www.apollographql.com/docs/react/">Apollo</a> project. It’s a prescriptive way to connect to a GraphQL backend, manage your cached data, and can even create inspectable pipelines across your entire stack.</p><p>The Apollo client is provided to your app through the aptly named ApolloProvider component exported from react-apollo. You can then declaratively configure your client via the various types of Apollo Links. The links come in different forms such as authentication, direct cache access, and HTTP.</p><p>A fairly standard implementation of an Apollo Client is as follows:</p><pre>// App.js<br>import React, { Component } from &#39;react&#39;<br>import { ApolloClient } from &#39;apollo-client&#39;<br>import { ApolloLink, concat } from &#39;apollo-link&#39;<br>import { ApolloProvider } from &#39;react-apollo&#39;<br>import { HttpLink } from &#39;apollo-link-http&#39;<br>import { InMemoryCache } from &#39;apollo-cache-inmemory&#39;</pre><pre>// Apollo HTTP Link<br>const httpLink <strong>= </strong>new HttpLink({<br>  uri<strong>: </strong>&#39;http://localhost:3000/graphql&#39;,<br>})</pre><pre>// Apollo Authentication Link<br>const authMiddleware <strong>= </strong>new ApolloLink((operation, forward) <strong>=&gt; </strong>{<br>  operation.setContext({<br>    headers<strong>: </strong>{<br>      authorization<strong>: </strong>localStorage.getItem(&#39;authToken&#39;)<br>    }<br>  })<br><br>  return forward(operation)<br>})</pre><pre>// Create Apollo Link with cache<br>const client <strong>= </strong>new ApolloClient({<br>  link<strong>: </strong>concat(authMiddleware, httpLink),<br>  cache<strong>: </strong>new InMemoryCache()<br>})</pre><pre>// Component<br>class App extends Component {<br>  render() {<br>    return (<br>      &lt;ApolloProvider client={client}&gt;<br>        &lt;YOUR COMPONENTS HERE /&gt;<br>      &lt;/ApolloProvider&gt;<br>    )<br>  }<br>}</pre><pre>export default App</pre><p>First off, heads up to the awesome team at Apollo for making the onboarding process so smooth and keeping excellent docs.</p><p>However, if you’re like us at <a href="https://hexientlabs.com/">Hexient Labs</a>, you hate repeating yourself whatsoever. So what’d we do? We abstracted the Apollo configuration into our own HOC!</p><h3>The `withApollo` HOC</h3><p>We’ve created our own basic HOC for integrating Apollo via composition (hint, it works great with compose from <a href="https://github.com/acdlite/recompose">recompose</a>)!</p><pre>// withApollo.js<br>import { ApolloClient } from &#39;apollo-client&#39;<br>import { ApolloLink, concat } from &#39;apollo-link&#39;<br>import { ApolloProvider } from &#39;react-apollo&#39;<br>import { HttpLink } from &#39;apollo-link-http&#39;<br>import { InMemoryCache } from &#39;apollo-cache-inmemory&#39;</pre><pre>// Apollo HTTP Link<br>const httpLink <strong>= </strong>new HttpLink({<br>  uri<strong>: </strong>&#39;http://localhost:3000/graphql&#39;,<br>})</pre><pre>// Apollo Authentication Link<br>const authMiddleware <strong>= </strong>new ApolloLink((operation, forward) <strong>=&gt; </strong>{<br>  operation.setContext({<br>    headers<strong>: </strong>{<br>      authorization<strong>: </strong>localStorage.getItem(&#39;authToken&#39;)<br>    }<br>  })<br><br>  return forward(operation)<br>})</pre><pre>// Create Apollo Link with cache<br>const client <strong>= </strong>new ApolloClient({<br>  link<strong>: </strong>concat(authMiddleware, httpLink),<br>  cache<strong>: </strong>new InMemoryCache()<br>})</pre><pre>// Preconfigured HOC<br>const withApollo = BaseComponent =&gt; props =&gt; (<br>  &lt;ApolloProvider client={client}&gt;<br>    &lt;BaseComponent {...props} /&gt;<br>  &lt;/ApolloProvider&gt;<br>)</pre><pre>export default withApollo</pre><p>Now our main component becomes purely functional and we can integrate our Apollo Provider with a simple wrapper (with help from recompose)!</p><pre>// App.js<br>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { compose, setPropTypes } from &#39;recompose&#39;<br>import withApollo from &#39;./withApollo&#39;</pre><pre>// Pure Component<br>const App = props =&gt; &lt;YOUR_COMPONENT {...props} /&gt;</pre><pre>// Enhancers<br>const withPropTypes = setPropTypes({<br>  client: PropTypes.any.isRequired, // Apollo client<br>})</pre><pre>export default compose(<br>  withApollo,<br>  withPropTypes,<br>)(App)</pre><p>Bahamamama! Cool right?</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e8e4dbcff3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/apollo-provider-hoc-70e8e4dbcff3">Apollo Provider HOC</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditional Rendering with Recompose]]></title>
            <link>https://medium.com/hexient-labs/conditional-rendering-with-recompose-6a69228d9245?source=rss----8a4f15c9336e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a69228d9245</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[recompose]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Mitch Masia]]></dc:creator>
            <pubDate>Fri, 16 Mar 2018 15:12:22 GMT</pubDate>
            <atom:updated>2018-03-16T15:12:22.139Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s take on non-ideal states the functional way.</p><h3>Non-Ideal State</h3><p>If you’re a frequent user of web or mobile apps, you’ve probably seen an empty or error state on a page. Many times, this will come in the form of a list-view with no results. Handling these states with a cute animation has become commonplace and makes for a delightful user experience.</p><p>In one of our React Native apps at <a href="https://hexientlabs.com/">Hexient Labs</a>, we handle the offline condition with a modal overlay:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*qSe91iJ6mZJ64n_YOitzqg.png" /><figcaption>Offline Modal with <a href="https://github.com/airbnb/lottie-react-native">Lottie</a> Animation</figcaption></figure><p>The modal above tells the user in a <em>friendly</em> way that something is wrong, and how to resolve it. So although the user has to take action, they aren’t too turned off.</p><p>These are the exact types of non-ideal states that UI designers and proficient developers have started implementing in their apps to provide a delightful user experience even under bad circumstances.</p><h3><strong>Recompose?</strong></h3><p><a href="https://github.com/acdlite/recompose">Recompose</a> by <a href="https://github.com/acdlite">Andrew Clark</a> is an excellent “utility belt” of higher-order functions that allow developers to enhance the functionality of their components via composition.</p><p>One of the most simple examples of this is using the setPropTypes and defaultPropsHOCs to enhance a functional component with some prop-type requirements and default props.</p><pre>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { compose, defaultProps, setPropTypes } from &#39;recompose&#39;</pre><pre>// Component<br>const Button = props =&gt; &lt;button {...props}&gt;{props.title}&lt;/button&gt;</pre><pre>// Enhancers<br>const withPropTypes = setPropTypes({<br>  onClick: PropTypes.func.isRequired,<br>  title: PropTypes.string.isRequired,<br>})</pre><pre>const withDefaultProps = defaultProps({<br>  onClick: () =&gt; {},<br>  title: &#39;Submit&#39;,<br>})</pre><pre>export default compose(withDefaultProps, withPropTypes)(Button)</pre><p>In the example above, the withPropTypes and withDefaultProps Higher-Order Components are composed together with the Button component to provide enhanced functionality without coupling them directly to the Button. In fact, these HOCs could be used in any component in our application!</p><p>So how can we use this same principle for conditional rendering??</p><h3>Enter the “branch” HOC</h3><p>The branch HOC is another utility function from Recompose that is commonly used with the renderComponent and renderNothing HOCs.</p><p>Here’s an example of rendering a List and a non-ideal state when it is empty:</p><pre>// List.js<br>import React from &#39;react&#39;<br>import PropTypes from &#39;prop-types&#39;<br>import { branch, compose, defaultProps, renderComponent, setPropTypes } from &#39;recompose&#39;<br>import EmptyState from &#39;../components/common/EmptyState&#39;<br>import Loader from &#39;../components/common/Loader&#39;</pre><pre>// Component<br>const List = props =&gt; (<br>  &lt;ul&gt;<br>    {props.data.map(item =&gt; &lt;li key={item}&gt;{item}&lt;/li&gt;}<br>  &lt;/ul&gt;<br>)</pre><pre>// Enhancers<br>const withPropTypes = setPropTypes({<br>  data: PropTypes.array.isRequired,<br>  loading: PropTypes.bool.isRequired,<br>})</pre><pre>const withDefaultProps = defaultProps({<br>  data: [],<br>  loading: false,<br>})</pre><pre>const withLoadingState = branch(<br>  props =&gt; props.loading,<br>  renderComponent(Loader),<br>)</pre><pre>const withEmptyState = branch(<br>  props =&gt; props.data.length === 0,<br>  renderComponent(EmptyState),<br>)</pre><pre>export default compose(<br>  defaultProps,<br>  withLoadingState,<br>  withEmptyState,<br>  withPropTypes<br>)(List)</pre><p>The example above composes our propTypes, defaultProps, loading state, and empty state together onto a single functional component List. The withLoadingState and withEmptyState can even be composed onto other components as well!</p><p>This is just one example of the power of Recompose- I’d highly recommend checking it out to encapsulate your rendering logic into functional pieces that are easily testable and composable.</p><p><a href="https://hexientlabs.com/"><em>Need help building your mobile or web app? Hexient Labs!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a69228d9245" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hexient-labs/conditional-rendering-with-recompose-6a69228d9245">Conditional Rendering with Recompose</a> was originally published in <a href="https://medium.com/hexient-labs">hexient-labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>