<?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[Handlebar Labs - Medium]]></title>
        <description><![CDATA[Building React Native &amp; Meteor apps and teaching others how to do the same. - Medium]]></description>
        <link>https://medium.com/handlebar-labs?source=rss----2b0347ae7102---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Handlebar Labs - Medium</title>
            <link>https://medium.com/handlebar-labs?source=rss----2b0347ae7102---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:37:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/handlebar-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[Instagram Style Double Tap with React Native]]></title>
            <link>https://medium.com/handlebar-labs/instagram-style-double-tap-with-react-native-49e757f68de?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/49e757f68de</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Thu, 06 Sep 2018 16:46:25 GMT</pubDate>
            <atom:updated>2018-09-06T16:46:24.371Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a host of ways to detect a tap in React Native — but how do you detect a double tap? Detecting double taps has a host of uses — like liking a picture, causing a scroll to top in a tab, etc. Let’s set up double tap detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*8GKBcCCUuRFV9zWwo837tg.gif" /></figure><p>We’ll start with a basic application that allows us to like a picture.</p><p>First create the app</p><pre>create-react-native-app IGStyleDoubleTap</pre><p>Then set up our app structure.</p><pre>cd IGStyleDoubleTap<br>mkdir src<br>mkdir src/images<br>touch src/index.js</pre><p>You’ll then want to download these <a href="https://github.com/HandlebarLabs/react-native-examples-and-tutorials/blob/master/tutorials/instagram-style-double-tap/src/images">heart icons</a> and put them in the src/images directory.</p><p>Next, paste the following in src/index.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/108099d267bf782ba5a543c55ae9a3cb/href">https://medium.com/media/108099d267bf782ba5a543c55ae9a3cb/href</a></iframe><p>Finally, replace App.js with the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea4308eb6a9fd11bd4846dc22f948e47/href">https://medium.com/media/ea4308eb6a9fd11bd4846dc22f948e47/href</a></iframe><p>With that you can yarn run ios or yarn run android and you can like a picture by pressing the heart icon below the picture.</p><p>With the setup complete we can actually start the implementation.</p><h3>Detecting a Double Tap</h3><p>This code is inspired by <a href="https://gist.github.com/brunotavares/3c9a373ba5cd1b4ff28b">this gist</a> by Github user <a href="https://github.com/brunotavares">brunotavares</a>.</p><p>First, we’ll wrap our Image component in a TouchableWithoutFeedback component, allowing us to detect the tap(s).</p><p>On our component we’ll track the last tap in a variable named lastTap. We’re not using component stated here as it doesn’t affect rendering in any way. It can default to a null value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1d37f481cc176dad91b0c44a0fc3c45/href">https://medium.com/media/a1d37f481cc176dad91b0c44a0fc3c45/href</a></iframe><p>Next, on our component we can set up a handleDoubleTap function in which we’ll compare the current tap to the last tap and, if it’s within the double tap threshold, call the appropriate function.</p><p>We’ll use Date.now() to compare values. Date.now() returns the milliseconds elapsed since January 1, 1970, 00:00:00 UTC which will work perfectly since our delay will be millisecond based.</p><p>Upon a successful double tap we’ll call the this.toggleLike() function otherwise we’ll update the this.lastTap value to be the result of Date.now().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1cc7a18b66b13b77b73471ee8721ea2/href">https://medium.com/media/e1cc7a18b66b13b77b73471ee8721ea2/href</a></iframe><p>We then need to wrap our Image component in a TouchableWithoutFeedback (make sure to import it from React Native!) to detect the tap(s).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89e7dd0bebabc945f1c892466be5fc19/href">https://medium.com/media/89e7dd0bebabc945f1c892466be5fc19/href</a></iframe><p>This results in the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*8GKBcCCUuRFV9zWwo837tg.gif" /></figure><h3>Refactoring the Double Tap Functionality to Its Own Component</h3><p>What we have now works perfectly fine — but it’s not very reusable. Lets refactor it into its own component so we can reuse it easily.</p><p>First, create a new file for the component.</p><pre>touch src/DoubleTap.js</pre><p>And paste the following to get started</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/468168c40d5407b6ee6493ddd15c893c/href">https://medium.com/media/468168c40d5407b6ee6493ddd15c893c/href</a></iframe><p>We can then go ahead and start moving logic over from src/index.js. First render.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc73493c83746b0367226a04ed1c197d/href">https://medium.com/media/bc73493c83746b0367226a04ed1c197d/href</a></iframe><p>The only difference from before is that we’re now rendering this.props.children inside of the TouchableWithoutFeedback so we can pass any component to it.</p><p>Next up let’s set up handleDoubleTap.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/faa8a8e87c46d9c2802d9acb87a4b085/href">https://medium.com/media/faa8a8e87c46d9c2802d9acb87a4b085/href</a></iframe><p>You can notice two differences here. First, instead of setting a state variable for our delay we’re accessing it via this.props.delay. That way the consumer of the component can override it. Second, we’re calling this.props.onDoubleTap() so the consumer can pass their own function down to the component.</p><p>Finally, we’ll set some default props so our component works regardless of if the consumer passes props.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c54dc95247db6403bd4ba7f8ddf10b/href">https://medium.com/media/03c54dc95247db6403bd4ba7f8ddf10b/href</a></iframe><p>Now let’s go ahead and use the new component. In src/index.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b22c2f5d910decdbd752a424d6a3e98/href">https://medium.com/media/5b22c2f5d910decdbd752a424d6a3e98/href</a></iframe><p>And there you have it! How to build an Instagram style double tap to like as well as how to refactor you code into reusable components.</p><p>The full source code is available on <a href="https://github.com/HandlebarLabs/react-native-examples-and-tutorials/blob/master/tutorials/instagram-style-double-tap/">Github</a>.</p><blockquote>Did you enjoy this tutorial? Check out other React Native tutorials <a href="https://github.com/HandlebarLabs/react-native-examples-and-tutorials">here</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49e757f68de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/instagram-style-double-tap-with-react-native-49e757f68de">Instagram Style Double Tap with React Native</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to Gestures in React Native]]></title>
            <link>https://medium.com/handlebar-labs/intro-to-gestures-in-react-native-e9b63dd3305?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/e9b63dd3305</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 18:23:06 GMT</pubDate>
            <atom:updated>2018-07-24T18:23:06.350Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial we’ll be learning to add gesture handling to a React Native app via PanResponder. In a <a href="https://www.fullstackreact.com/articles/build-your-own-javascript-navigator-for-react-native/">previous tutorial</a> I walked through building a basic JavaScript based navigator for React Native which will serve as the basis of this tutorial.</p><h3>Getting Started</h3><p>We’ll be using create-react-native-app to build our app. To get started run the following from your terminal:</p><pre>create-react-native-app rn-js-navigator<br>cd rn-js-navigator</pre><p>Replace App.js with</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe4b3e559c6206b227570ee59c2b55eb/href">https://medium.com/media/fe4b3e559c6206b227570ee59c2b55eb/href</a></iframe><p>and then create a new file, Navigator.js, with the following contents</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c588e43aa4599d6bac3a8c4c0f8a6340/href">https://medium.com/media/c588e43aa4599d6bac3a8c4c0f8a6340/href</a></iframe><p>We can now setup the gestures. The only gesture we’re going to have is, when you’ve got multiple screens in the stack, you can swipe back to the previous one.</p><h3>PanResponder Setup</h3><p>First we need to import PanResponder from React Native.</p><p>We’ll then go ahead and initialize a new pan responder on our component.</p><p>Navigator.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8b835c240b8377fb47b00594b5bb2ee/href">https://medium.com/media/b8b835c240b8377fb47b00594b5bb2ee/href</a></iframe><p>Let’s walk through what each of these functions does before we start defining them.</p><ul><li>onMoveShouldSetPanResponder: This determines whether our pan responder should actuallly do anything. For this example we want the pan responder to be enabled on all but the first screen and only when the gesture started in the left most 25% of the screen.</li><li>onPanResponderMove: When the pan responder is enabled and the move is detected, what should happen? This one gets called a lot.</li><li>onPanResponderTerminationRequest: If something else wants to take over gestures, should it be allowed to?</li><li>onPanResponderRelease: When the gesture is released/completed, what should happen? For us, if the gesture took up more than 50% of the screen we&#39;ll complete it, otherwise we&#39;ll keep the user on the current screen.</li><li>onPanResponderTerminate: When the gesture is terminated (meaning another component became the responder) what should we do? We&#39;ll reset to the current screen.</li></ul><p>Finally, we need to actually apply the pan handlers to our container component.</p><p>Navigator.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/471b7bdb887ed105df5317936bff58d2/href">https://medium.com/media/471b7bdb887ed105df5317936bff58d2/href</a></iframe><p>Now to start the implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fcd1a762fb5f38d52da7aa93bb537a1/href">https://medium.com/media/0fcd1a762fb5f38d52da7aa93bb537a1/href</a></iframe><p>First we check if we’re on the first screen by analyzing this.state.stack, which represents the currently active screens. We then check where the gesture first started by looking at evt.nativeEvent.pageX and see if it&#39;s within the left most 25% of the screen.</p><p>We then check whether or not we should actually start responding to the gesture! We should only respond if we’re on screen 2+ and if the gesture started in the left quarter of the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4359a6313c0c7c4ae65d5c9cb4c7cfc1/href">https://medium.com/media/4359a6313c0c7c4ae65d5c9cb4c7cfc1/href</a></iframe><p>Now, once the pan responder has been enabled we’ll update this._animatedValue, which drives our offset, to be whatever the value that is provided. gestureState.moveX is going to be wherever the user&#39;s finger is on the x axis.</p><p>You can actually go ahead and test it now. It’s working but when you let go/stop the gesture the screen just sticks there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6725eb762ac07218a3e2d1b3d835a730/href">https://medium.com/media/6725eb762ac07218a3e2d1b3d835a730/href</a></iframe><p>To fix that we need to implement onPanResponderRelease. In this function we&#39;re going to check if wherever the user released the screen was in the right 50% of the screen. If it was then we&#39;ll call the this.handlePop function to finish the animation and pop the screen off the stack.</p><p>If the screen wasn’t in the right most 50% then we’ll reset the screen offset to 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9a10c08c969ddc14763dbfff58f3364/href">https://medium.com/media/b9a10c08c969ddc14763dbfff58f3364/href</a></iframe><p>And when the pan responder is taken over we’ll reset the screen to a 0 offset.</p><p>All of this leaves us with the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*b7ZwCOn4GOAg4gKugaTUGw.gif" /></figure><p>The final Navigator.js is</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/319e311d3721c87a65ecce166c840cc5/href">https://medium.com/media/319e311d3721c87a65ecce166c840cc5/href</a></iframe><p>You can find a running example <a href="https://snack.expo.io/@spencercarli/basic-javascript-navigator-example">on Snack</a>.</p><p>I hope you found this example fun and valuable! If you’re interested in learning more about React Native checkout my <a href="https://learn.handlebarlabs.com/p/react-native-basics-build-a-currency-converter">free basics of React Native course</a>! Or, if you’re further along, checkout my <a href="https://learn.handlebarlabs.com/p/learn-to-send-react-native-apps-to-production">Production Ready React Native course</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9b63dd3305" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/intro-to-gestures-in-react-native-e9b63dd3305">Intro to Gestures in React Native</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Questions to Ask When Choosing a Push Notification Provider for a React Native App]]></title>
            <link>https://medium.com/handlebar-labs/4-questions-to-ask-when-choosing-a-push-notification-provider-for-a-react-native-app-fc0949eebc40?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/fc0949eebc40</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Wed, 21 Mar 2018 15:09:36 GMT</pubDate>
            <atom:updated>2018-04-18T15:51:23.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvTqFy7xBkSpSnxXW4faZw.png" /></figure><p>Push notifications rock. Twice a day I’m reminded about how I can win some 💰 💰 💰 by playing a trivia game. Or I’m sent a daily news digest. Or Twitter tells me someone I follow liked a tweet (🙄).</p><p>But how do I do it in my app? Specifically in my React Native app?</p><p>If you’ve looked into push notifications you’ve likely decided you don’t want to manage it all on your own, especially if you’re targeting both iOS and Android.</p><p>But that brings up the question — who do I choose? There are a lot of options.</p><p>Here’s a few questions to ask yourself.</p><h3>Question #1: Are you using Expo?</h3><p><strong>If no, </strong>move on to question 2.</p><p><strong>If yes</strong>, then use their push notification service! A few things about their push notification service</p><ul><li>It’s crazy easy to setup (as with some many things related to Expo).</li><li>There are multiple server sdks to easily integrate with your backend (and a REST API if you’re using something different).</li><li>They’ve got an awesome <a href="https://expo.io/dashboard/notifications">push notification tool</a> that can help you build push notifications without having to deal with the backend (great for testing &amp; prototyping).</li><li>The doc/guide is incredible clear.</li><li>Oh, and it’s free.</li></ul><p><a href="https://docs.expo.io/versions/v25.0.0/guides/push-notifications.html#content">Push Notifications | Expo latest documentation</a></p><h3>Question #2: Privacy or Price?</h3><p><strong>If privacy is your #1 priority, </strong>move on to question 3.</p><p><strong>If price is your #1 priority,</strong> I see you as having two primary options (that I’m familiar with, I’m sure there are others).</p><h4>OneSignal</h4><p>OneSignal is a service that delivers push notifications. They</p><ul><li>Are free (unlimited devices, unlimited notifications, testing, localization, etc.)</li><li>Are used by a lot of big name companies</li><li>Have a nice API and nice web dashboard (nice for non-developers to be able to send push notifications)</li><li>Have, overall, a great developer experience (speaking from experience)</li></ul><p>The con? What they do with your data. They’re a free service — but they’ve got to make money. How? By selling data it collects.</p><blockquote>OneSignal makes money by selling data to advertisers and research companies. We also offer paid service options for clients that require increased data privacy.</blockquote><p><a href="https://documentation.onesignal.com/docs#section-why-should-i-use-onesignal">Source</a></p><p>Is this inherently bad? No! They provide a great service and a great developer experience. But it’s something to consider. They do provide a paid service that require increased data privacy. No personal experience on that front.</p><p><a href="https://onesignal.com/">Customer Engagement Platform for Email, Push Notifications, &amp; SMS</a></p><h4>Firebase Cloud Messaging</h4><p>Firebase Cloud Messaging (Firebase is a Google product) gives you a way to send push notification from within the Google environment. As far as I can tell it’s completely free and you (seemingly) don’t need to be using Firebase in any other capacity to use it.</p><p>I don’t have a ton of experience on this front but it seems that third party packages in React Native struggle a bit with integration. I might be wrong on this though.</p><blockquote>Correction: I am wrong about this! <a href="https://medium.com/u/20ddff065da7">Chris Bianca</a> mentioned in a comment that there have been changes to the push notification integration in react-native-firebase. <a href="https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1">More info</a>.</blockquote><p><a href="https://firebase.google.com/docs/cloud-messaging/">Firebase Cloud Messaging | Firebase Documentation</a></p><blockquote>Interested in learning some push notification best practices? I put together <a href="http://www.handlebarlabs.com/m/react-native-push-notifications/">a quick video</a> sharing a few must-follow rules.</blockquote><h3>Question #3: Are You in the AWS Ecosystem?</h3><p>You’ve got a few options here. In a past project I worked with AWS Simple Notification Service (SNS). It’s powerful but, compared to other options, requires much more configuration.</p><p>The other drawback is that there isn’t any way to easily send non-system generated messages (no admin interface). It’s cheap to use though!</p><p><a href="https://aws.amazon.com/sns/">Push Notification Service - Amazon Simple Notification Service - AWS</a></p><p>Also, in the AWS world is AWS Amplify Push Notifications. This just came out in the last few weeks so I don’t have experience with it but, if you’re using AWS Amplify already, this could be a great option for you!</p><p><a href="https://aws.github.io/aws-amplify/media/push_notifications_setup">Push Notifications</a></p><h3>Question #4: Why Do You Have so Many Questions? 😄</h3><p>Now that we’re here you’re going to have to do more research and make the decision on your own. There are multiple options that you could choose from (including rolling your own system). I won’t leave you completely hanging though. Here’s some other services and packages that may help you out.</p><ul><li><a href="https://www.urbanairship.com/">Urban Airship</a>. <a href="https://github.com/urbanairship/react-native-module">Official React Native Library</a>.</li><li><a href="https://www.pushwoosh.com/">Pushwoosh</a>. <a href="https://github.com/Pushwoosh/pushwoosh-react-native-plugin">Official React Native Library</a>.</li><li>General use push notification package: <a href="https://github.com/zo0r/react-native-push-notification">react-native-push-notification</a>.</li></ul><blockquote>Push notifications are hard. Not only setting them up, but knowing how to use them. I put together a quick video sharing some best practices for push notifications. <a href="http://www.handlebarlabs.com/m/react-native-push-notifications/">Get it here</a>. Your users will thank you!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc0949eebc40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/4-questions-to-ask-when-choosing-a-push-notification-provider-for-a-react-native-app-fc0949eebc40">4 Questions to Ask When Choosing a Push Notification Provider for a React Native App</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How  dad jokes helped me better understand immutable data]]></title>
            <link>https://medium.com/handlebar-labs/how-dad-jokes-helped-me-better-understand-immutable-data-d4256a0d4eea?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/d4256a0d4eea</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Wed, 07 Mar 2018 16:16:55 GMT</pubDate>
            <atom:updated>2018-03-07T16:16:54.656Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently started working on a course regarding React Native and push notifications (how to, strategy, etc.).</p><p>With that, I had to put together an example app — I decided on an app that will show you some 💩 dad jokes. You can swipe through them in an ever-so-popular Tinder like card interface.</p><p>The app fetches 3 jokes and then, as you swipe jokes away, I make a request for new ones — adding those new jokes to my array of 💩 dad jokes.</p><p>It didn’t all work out perfectly though. The issue? When I got a new question it would bring me back to the very first joke. Like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*dkcCbxz4aPfti5WtQCCGxg.gif" /><figcaption>Dem jokes though</figcaption></figure><p>So, what’s happening? Initially I request 3 jokes before we render any. This gives me an array of jokes like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8948cfc0e87103455d2a3e5e07ebb46/href">https://medium.com/media/e8948cfc0e87103455d2a3e5e07ebb46/href</a></iframe><p>If I get rid of the request-new-joke-on-swipe functionality everything works fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*bD9nkYzKaub8pIA6Ow1NHA.gif" /></figure><p>That makes me think the issue is related to that array changing…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df0f972d132eaff3871eb5e319d57214/href">https://medium.com/media/df0f972d132eaff3871eb5e319d57214/href</a></iframe><p>Initially I had assumed the swiping component I was using (react-native-deck-swiper) could handle the changing array and would append those results to the existing stack.</p><p>That wasn’t true — and wasn’t a good assumption on my part.</p><p>Since I’m creating a new jokes array and saving it to state on each new joke request (this is the right way to do it since you don’t want to mutate existing state) I needed to better handle this.</p><p>What I found was that, each time I got a new joke, the swiper component re-rendered and, by default, the swiper component would render the card at index 0 — which was always the very first joke in my array.</p><p>Fortunantely, you can override this via a prop of cardIndex so all I have to do is</p><ol><li>Track the current card index</li><li>Pass that index to my swiper component</li></ol><p>Easy. Each time I swipe a card away I’ll increment my cardIndex, stored in component state, and then pass this.state.cardIndex to the Swiper component.</p><p>That results in the following interaction</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*SQGs0oFVuqUgV5154RgFeg.gif" /><figcaption>Now you can have quick access to all the 💩dad jokes you can handle</figcaption></figure><p><a href="https://snack.expo.io/B1N7JqT_G">You can find the complete code on Snack</a>.</p><p><strong>Have questions about react native &amp; push notifications? Let me know!</strong></p><blockquote>Interested in having 🔥🔥🔥 React (Native) tips emailed to you on a weekly basis? Sign up for my <a href="http://www.handlebarlabs.com/m/email-list/">email list</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4256a0d4eea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/how-dad-jokes-helped-me-better-understand-immutable-data-d4256a0d4eea">How 💩 dad jokes helped me better understand immutable data</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create Tech Tutorials]]></title>
            <link>https://medium.com/handlebar-labs/how-to-create-tech-tutorials-7f3ecdc29f82?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/7f3ecdc29f82</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Tue, 14 Nov 2017 15:31:41 GMT</pubDate>
            <atom:updated>2017-11-14T15:31:41.278Z</atom:updated>
            <content:encoded><![CDATA[<p>People often ask me how I write tech tutorials. I’ve given partial answers time and time again, but I wanted to cover it all at once so that you know what I typically put into a tutorial and how you can plan one out.</p><p>To date, I’ve written over 60 free tutorials, recorded many free videos, and over 100 videos for my various courses. So I’ve got some experience.</p><p>And before you say that “this isn’t for me” — we’ve all got something unique to share so please don’t think you can’t do it, no matter how junior you may be! I started writing tutorials as a way to better understand what I was doing day to day in my job.</p><h3>Choosing the Topic</h3><p>I don’t have much of a system for choosing a topic but it typically falls into one of three categories</p><ol><li>“Docendo discimus” (by teaching, we learn) — if I’m learning something new and I want to understand it fully I try to teach it. This makes me go through code line-by-line and explain it.</li><li>I use something, and it helps me — maybe it’s push notifications, maybe it’s Meteor + React Native. If I use something and I think others could also use it, I share that knowledge.</li><li>I’m asked about something. I receive 50+ tech related emails a week. If a question comes up a lot, I write a tutorial about it.</li></ol><h3>The Code</h3><p>A tech tutorial is going to, most likely, involve some code. Don’t try to write the code while you’re also writing/recording the tutorial. For me, it just doesn’t work out and ends up in a low-quality pile of 💩.</p><p>Write the code first.</p><h3>Planning the Tutorial</h3><p>Outlines are everything! My outlines are bare bones and just a simple headline that represents the goal of that section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7XXCDrKeKPipkQ_cOBRlw.jpeg" /><figcaption>#Meta. My outline for this post.</figcaption></figure><p>If I’m recording a video, I’ll put together a “shot list” which is just a series of shots I want to record. A section will have anywhere from 5 to 15 shots. This helps me record the video in short segments, allowing me to re-record segments when I make mistakes, and edit it all together later on.</p><p>I’ll typically form my outline in the following way:</p><ol><li>Take my code example and comment out everything directly related to the concept I’m trying to teach</li><li>Create a repo/branch with the starting point of the code for the tutorial</li><li>Uncomment pieces of code in related segments, making my sections. My goal is that every section can be run on its own.</li><li>Make a repo/branch with the finished code</li></ol><p>A note on the starting point: Think about your target audience. What do they already know? Don’t worry about basic setup if you’re targeting an intermediate/advanced audience. Just give them code that works and if they want to know all the details they can read the code over.</p><h3>Creating the Tutorial</h3><p>When it’s time to create the tutorial most of the work is done. You just need to describe what you’ve done and piece it all together.</p><p>Why did you write the code in this way? What can they expect as a result? What issues might they encounter? How do they fix those problems?</p><blockquote>Protip: Avoid rambling/getting off topic. Try to stay focused on the topic you’re teaching. I struggle with this a lot on video, which is why I try to record in a series of short clips.</blockquote><p>If you’re recording video: TAKE YOUR TIME. It’s hard. You’re going to make mistakes. Figure out how to make those mistakes low stakes.</p><h3>Edit the Tutorial</h3><p>For a while, I didn’t edit my tutorials. When I finished them I wanted to publish them. It works fine but it can cause issues for your audience when things don’t quite line up. A simple restructure of the sentence could clear everything up!</p><p>I’ll typically write and edit on different days. I also try to do it at a different time of day so I’m in a different state of mind. I want things to be super clear and make minimal assumptions.</p><p>I do this full time and I’m still using Quicktime and iMovie to produce videos. If I’m writing I’ll often write directly in Medium or use Grammarly to ensure my writing is decent.</p><h3>Share the Tutorial!</h3><p>The moment you’ve been waiting for! Press “Publish” and share it! Where does your target audience hang out? Is it HackerNews, Twitter, a Facebook Group, Reddit, etc.? Maybe Medium is a good place to post it? This is my weak point, but I’m learning!</p><p>So that’s my process. How much time does it take? Well, for a 2 part series on React Native + GraphQL Authentication I spent upwards of 13 hours putting it together.</p><p>Holy shit that’s a lot of time! Yeah, it is, but I love doing it and that was a big series (20 minutes reading, 1 hour of video). Your tutorials don’t have to be that long at all. Keep it simple and write something.</p><p>I hope you found this little post helpful!</p><p><strong>Have more questions about creating tech tutorials? Let me know!</strong></p><blockquote>My name is Spencer. I teach people to become full stack mobile developers using React Native, GraphQL, Meteor, and more. If this sounds like something you’re interested in <a href="http://www.handlebarlabs.com/m/react-native/">sign up for my email list</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f3ecdc29f82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/how-to-create-tech-tutorials-7f3ecdc29f82">How to Create Tech Tutorials</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating Navigation in React Native]]></title>
            <link>https://medium.com/handlebar-labs/navigating-navigation-in-react-native-26c7e4690f94?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/26c7e4690f94</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Mon, 13 Nov 2017 16:20:40 GMT</pubDate>
            <atom:updated>2017-12-14T19:22:30.999Z</atom:updated>
            <content:encoded><![CDATA[<h4>An Opinionated Take on the Current State of Navigation in React Native</h4><blockquote>This is an adaptation of a talk I recently did at <a href="https://www.meetup.com/NashReact-Meetup/">NashReact</a>. You can view the slides in their entirety <a href="https://www.slideshare.net/secret/v1VZyoDseUhs4W">on SlideShare</a>.</blockquote><p>You’re new to React Native. Or maybe you’re about to start on a big project that uses React Native.</p><p>You’re bound to ask the question — “which navigator do I use?”.</p><p>And if you head to google you’re likely to find a few options…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0esbjdGMZ2_d1jP7n_gaA.png" /></figure><p>Those were only the first few I could think of — no doubt that there are more! So, <em>why is it like this?</em></p><h3>Two Categories of Navigators</h3><p>You can break all navigation solutions for React Native into two categories — JavaScript and Native.</p><p><strong>Javascript </strong>navigators are written entirely in JavaScript and executed entirely in JavaScript.</p><p><strong>Native</strong> navigators are navigators written in the platform’ss native language (typically Objective-C or Java) and are exposed to React Native via a JavaScript API. The primary difference is that navigation is executed off of the JavaScript thread.</p><h3>But Why so Many Options?</h3><p>Totally valid question — it seems like two solutions would give, right? Not in JavaScript land! Let me give you a brief (personal) history lesson…</p><p>I started using React Native full-time very soon after it was open-sourced (within weeks). So I’ve tried quite a few navigation solutions in the products I’ve worked on. I’ll introduce you to the ones I used daily and had dozens of hours invested in:</p><h4>NavigatorIOS</h4><ul><li>Birth: React Native is released</li><li>Pro: Used the actual iOS native navigator</li><li>Con: iOS Only</li><li>Death: Android support added to React Native</li></ul><p>When React Native first came out not a ton of people were using it, there was one navigation solution, and you pretty much did things in one way (because it was so new). <em>NavigatorIOS</em> worked beautifully in this world, until Android came along.</p><h4>Navigator</h4><ul><li>Birth: Android support added to React Native/React Native release</li><li>Pro: JavaScript based — completely cross platform</li><li>Con: Somewhat confusing, though cross platform it wasn’t designed for both platforms, potential for performance issues</li><li>Death: Community take over/NavigationExperimental</li></ul><p>When we started working on Android support we switched to the <em>Navigator</em> component. It seemed like the most natural progression and was one of the official navigators. It wasn’t perfect though.</p><h4>ExNavigation</h4><ul><li>Birth: Pain from <em>Navigator</em> component</li><li>Pro: Cross platform, great defaults, easy to use</li><li>Cons: Limited in its breadth of functionality, potential for performance issues</li><li>Death: React Navigation</li></ul><p><em>ExNavigation</em>, to this day, has my favorite API of any navigator. It was easy to pick up and easy to use in my tutorials and <a href="https://learn.handlebarlabs.com/">courses</a>. But, like everything, it wasn’t perfect. The project I was working needed more customized navigation solutions (designers 🙄😉)</p><h4><strong>NavigationExperimental</strong></h4><ul><li>Birth: Need for a better &amp; more configurable navigator</li><li>Pro: Highly configurable</li><li>Con: Confusing, experimental, potential for performance issues</li><li>Death: React Navigation</li></ul><p>NavigationExperimental was, as you can guess from the name, an experiment in building a more configurable navigation solution. It was confusing though — I used it for months and, honestly, don’t think I ever really got a grasp on it.</p><h3>Navigation Today</h3><p>You may have noticed that the last two navigation solutions I used died off as a result of the same navigation library so, the undisputed champion of navigation in React Native is…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*6TYqMppsXPc0yo95nyisPA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8idvphJi39WZj0oiyroNQ.png" /><figcaption>React Navigation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Uh05lX9WIx0XJkU7VojKUQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*sgkFfbncLnz8B4HI5eoqXw.png" /><figcaption>React Navigation Feedback</figcaption></figure><p>The reality is that all of those navigation solutions I showed you earlier still exist, and more. But I think I can help you make your decision easier…</p><h3>The Primary Contenders</h3><p>In the JavaScript corner we’ve got <a href="https://reactnavigation.org/"><em>React Navigation</em></a><em> </em>and in the Native corner we’ve got <a href="https://wix.github.io/react-native-navigation/#/"><em>React Native Navigation</em></a>.</p><blockquote>“Why not X? It’s way better than those pieces of junk!” Everything has their pros and cons. These are the ones that I see having the most flexibility, greatest adoption, and continued support.</blockquote><blockquote>Also, I told you this was opinionated.</blockquote><p>So, between these two navigators, which should you choose?</p><h4>First: Environment Considerations</h4><p>Before you start weighing the pros and cons of each of these solutions you’ll have to find out if you can actually choose between them.</p><p>If you’re using <a href="https://expo.io/">Expo</a> or <a href="https://github.com/react-community/create-react-native-app">Create React Native App</a> to build your React Native app, tools that make building RN apps much easier, you’re going to be in the <em>React Navigation </em>camp. That’s because, as part of what makes those tools so easy to use, you don’t have access to the native parts of the React Native app — which <em>React Native Navigation</em> requires.</p><p>Therefore, if you choose to build an app with either of those tools (which is how I build apps 90% of the time), you’ll be rocking <em>React Navigation</em>.</p><p>With that being said, if you start your React Native app via react-native init you can use <em>React Navigation</em> or <em>React Native Navigation </em>because you’ve got access to the native portions of your RN app (the <em>ios/</em> and <em>android/</em> directories).</p><h3><a href="https://reactnavigation.org/">React Navigation</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*SQA56vYHT62QmpEMFIFW3g.png" /></figure><h4>Features</h4><ul><li>Simple installation — it’s just an npm package</li><li>Navigators are simply components</li><li>Stack navigator, tab navigator, and drawer navigator are built in</li><li>Platform specific components (navbar on iOS looks like it should, navbar on Android looks like it should)</li><li>Customizable but intelligent defaults</li></ul><h4>Drawbacks</h4><ul><li>Easier to make poor performance apps because it all runs on the JavaScript thread (you can minimize/eliminate this though)</li><li>Can be confusing. This is mostly a documentation &amp; example problem (working on it!)</li></ul><h3><a href="https://wix.github.io/react-native-navigation/#/">React Native Navigation</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*lPYG2cGAo7Qet0nd6_szPA.png" /></figure><h4>Features</h4><ul><li>It’s performant and it’s hard to break that. That’s because navigation is happening off the JavaScript thread</li><li>It uses the “real” navigation components (header, tab bar) because it’s interfacing with the native components</li><li>It’s simple to use, once it’s installed</li><li>Minimal boilerplate, once it’s installed</li></ul><h4>Drawbacks</h4><ul><li>Complex installation for non-native developers (like me). For example, when putting together my demo for the talk, I couldn’t debug a simple issue I made when installing because I just don’t know Android native stuff</li><li>Harder to use non-Redux state management solutions (though work arounds exist)</li><li>No way to statically define route configuration (personal preference of mine)</li></ul><p>You can view a comparison of these two navigators by running either of the projects in this repo.</p><p><a href="https://github.com/spencercarli/navigation-comparison">spencercarli/navigation-comparison</a></p><p>In conclusion: there are a lot of great navigation solutions out there but at the end of the day I would be looking at <a href="https://reactnavigation.org/"><em>React Navigation</em></a><em> </em>or <a href="https://wix.github.io/react-native-navigation/#/"><em>React Native Navigation</em></a> for my navigation needs. They’re both great libraries.</p><blockquote>Navigation is just one aspect of your app. If you’re interested in what my exact development environment is and the steps I take for every React Native app I build, check out <a href="https://learn.handlebarlabs.com/p/how-to-set-up-a-new-react-native-project">this free series.</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26c7e4690f94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/navigating-navigation-in-react-native-26c7e4690f94">Navigating Navigation in React Native</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL Authentication with React Native & Apollo [Part 2/2]]]></title>
            <link>https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-2-2-13ac8c362113?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/13ac8c362113</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Mon, 06 Nov 2017 19:22:05 GMT</pubDate>
            <atom:updated>2018-01-22T22:46:29.972Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fwe-6psYmeU2QkM9zVNkWQ.jpeg" /></figure><h4>Connecting a React Native app to the Backend</h4><p>This is the second and final part of a series where I cover how to setup authentication with React Native, GraphQL, and MongoDB. Below is part 1 where we setup the server.</p><p><a href="https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-1-2-9613aacd80b3">GraphQL Authentication with React Native &amp; Apollo [Part 1/2]</a></p><p>In this part we’ll be building a basic React Native app and connecting it to the backend. We’ll be using <a href="http://snack.expo.io/">Snack</a> to do this so you never have to leave your browser.</p><h3>Prefer Video?</h3><p>I made a video version of this tutorial as well, which can be found below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFf2N_MnntCE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFf2N_MnntCE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFf2N_MnntCE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/28cbcb6de5414caeae2bb504dbb2e826/href">https://medium.com/media/28cbcb6de5414caeae2bb504dbb2e826/href</a></iframe><h3>Setup</h3><p>We’re focusing on the React Native + Apollo aspect in this tutorial so we won’t be walking through the process of building the UI, below is the Snack with all the components setup.</p><blockquote>Note: I had some inconsistency/issues when using native-base on Snack. If you’re having those issues you can run the app locally instead. <a href="https://github.com/spencercarli/react-nativegraphql-auth-client">Here’s a the repo</a>.</blockquote><p><a href="https://snack.expo.io/@spencercarli/graphql-authentication-starting">https://snack.expo.io/@spencercarli/graphql-authentication-starting</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*9O5aNy79Xs-dMj-CPbKEeQ.gif" /></figure><p>As you can see, there’s not much to it right now. It’s just a bunch of fake verification and UI code.</p><h3>Connecting to the Backend</h3><p>Before we move on make sure that you’ve got the URL for your GraphQL endpoint from Launchpad — available in the bottom center of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mprh0T3bv864EwFK9mHLTA.png" /><figcaption>Mine is <a href="https://xnmjwwlpml.lp.gql.zone/graphql">https://xnmjwwlpml.lp.gql.zone/graphql</a></figcaption></figure><p>Now let’s configure the ApolloClient (note that these instructions are for Apollo v2).</p><p>We’ll be using a handful of packages throughout this tutorial. When you import than Snack will automatically install them (if you’re not using Snack then you need to install them from NPM).</p><p>To setup the Apollo client we can useapollo-client-preset. At the top of your app.js file add import { ApolloClient, HttpLink, InMemoryCache } from &#39;apollo-client-preset&#39;;</p><p>Then create a new ApolloClient instance that points at the GraphQL endpoint.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d81f3d87a689c8d983d4c4fc8364b5/href">https://medium.com/media/94d81f3d87a689c8d983d4c4fc8364b5/href</a></iframe><p>To make this available to our app we need to use ApolloProvider, pass it the new client, and wrap our app with it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0283618280a207277364bdd233137b/href">https://medium.com/media/6a0283618280a207277364bdd233137b/href</a></iframe><p>We should be connected to the backend! Now to interact with it.</p><h3>Registering Users</h3><p>If you take a look in Register.js you’ll see that I’ve got some simple logic in place to capture input values, check them, etc. The basics. Now, when a user presses submit, we want to:</p><ol><li>Attempt to log them in via the signup mutation</li><li>If successful, save the jwt to AsyncStorage</li><li>Switch the view the user sees</li></ol><p>To accomplish #1 we need to make the Register component aware of the mutation. We’ll use gql to write our graphql query and the graphql higher order component to tap into the Apollo client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d418af01786bf6056d7df3a33610c68e/href">https://medium.com/media/d418af01786bf6056d7df3a33610c68e/href</a></iframe><p>We know that our mutation looks something like this (from working with it directly in Launchpad in part 1).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3750931e54ed78ba988400737039dd86/href">https://medium.com/media/3750931e54ed78ba988400737039dd86/href</a></iframe><p>Now we need to to be able to pass variables from our user to the mutation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd5cccb74b940ac2f9f1764900f2f409/href">https://medium.com/media/dd5cccb74b940ac2f9f1764900f2f409/href</a></iframe><p>Finally, we want to make this mutation available to the Register component via this.props so that the component agnostic from the Apollo bindings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/953bf3cc60109ef4ec56fb33b14ad464/href">https://medium.com/media/953bf3cc60109ef4ec56fb33b14ad464/href</a></iframe><p>Now to use it we’ll go to the end of our handleSubmit function and call it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f97a1756df2288a2a3aa5645af76f72f/href">https://medium.com/media/f97a1756df2288a2a3aa5645af76f72f/href</a></iframe><p>That’s only taking care of a piece of the puzzle though. The signup function will return a promise so we can append then and catch to it. When the response is successful we want to save the JWT and we want to show them the profile screen. Both of these will be handled in the changeLoginState that’s being made available on this.props.screenProps.</p><p>Also, when an error occurs, we want to highlight the field that caused the error. Note that this is very basic error handling and is not covering all potential errors.</p><p>With those considerations in mind that leaves us with</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1cc7a5afc1ef78e3eb2c91d631a86cf/href">https://medium.com/media/d1cc7a5afc1ef78e3eb2c91d631a86cf/href</a></iframe><p>Now let’s improve on that changeLoginState function which is being made available in app.js. It’s already changing to the profile screen for us but we also want to save the JWT.</p><p>We’ll be using the signIn and signOut functions from util.js, which are just wrappers around AsyncStorage. Take a moment to understand them.</p><p>So if the user is loggedIn save the JWT with the signIn function, otherwise sign them out with signOut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48867530cd4fecb17b9cb8cfcb5499de/href">https://medium.com/media/48867530cd4fecb17b9cb8cfcb5499de/href</a></iframe><p>Great! Now the JWT will be saved and the profile screen will be shown. But as it stands if the app refreshes they’re still shown the sign up screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*e-0xb9b3HYJRnVHJ6pjo2A.gif" /></figure><h3>Login with JWT</h3><p>After signing up they get their JWT and it’s saved to persistent storage (AsyncStorage). We can use this to sign in. All we’ll do is, in app.js, is check if they have a token in AsyncStorage and if so show them the profile.</p><blockquote>Note: This is a very trivial implementation. This could be a place where you check if the JWT the user has is still valid and only <em>then</em> show them the profile screen. In the interest of brevity I’ll be skipping that.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e67627f1e695954ff0149fa657707f38/href">https://medium.com/media/e67627f1e695954ff0149fa657707f38/href</a></iframe><p>getToken is also a small wrapper around AsyncStorage.</p><p>This leaves us with the following interaction: when the app is refreshed the user will be automatically logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*54oaV5Vti_LSb1E-YsUfAA.gif" /></figure><h3>Sign Out</h3><p>Since it’s something we need to do to continue on with this tutorial, and our app needs it. We’ll implement signing out.</p><p>Actually, if you think back to where we modified handleChangeLoginState we already did everything necessary. When the user is changing their loggedIn state to false we clear the AsyncStorage token that is used to sign in.</p><p>So we’re done! Click “Log Out”, refresh the app, and you’ll see it no longer brings you to profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*jYJFBQB4T7K68StF0KaIlw.gif" /></figure><h3>Login with Email and Password</h3><p>Logging in with email and password is just like sign up, we’re just calling a different mutation. I’ll let the code do the talking.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25e7e507584852febd3a2b6f018bd372/href">https://medium.com/media/25e7e507584852febd3a2b6f018bd372/href</a></iframe><p>Now to call the login function available on this.props, save the JWT and change screens (on success) or show an error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f71896d08796d66344ad9d7f8442116c/href">https://medium.com/media/f71896d08796d66344ad9d7f8442116c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*XMyBCLDrUdWAubSpfIS7gw.gif" /></figure><h3>Showing User Information</h3><p>The final thing we’ll do, to demonstrate that things are actually working and it’s not just a big facade, is show the user’s database _id and their email address. We can do that via the currentUser query we set up in Part 1.</p><p>This work will happen in the Profile.js file.</p><p>The query is very simple, we can just copy exactly what we had in part 1. Put this query inside a graphql higher order component as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/088e1f54758f985b4a30788cda043cbd/href">https://medium.com/media/088e1f54758f985b4a30788cda043cbd/href</a></iframe><p>We pull currentUser off of this.props.data and display the data, if it exists.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21455b571c069f435fd9996a11554a79/href">https://medium.com/media/21455b571c069f435fd9996a11554a79/href</a></iframe><p>If you refresh the app now you’ll see that nothing is changing? Why is that?</p><p>Well we’re not passing the JWT along with our request! The server is expecting the JWT to be coming in the authorization header and uses that to find the current user.</p><p>To pass this token along with the request we’ll use setContext from the apollo-link-context which is another apollo link we’ll use. First pull the HttpLink we currently have into a variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c17c7cd7019479ee4e0406d576c17a60/href">https://medium.com/media/c17c7cd7019479ee4e0406d576c17a60/href</a></iframe><p>Then, using setContext, we’ll create a new authLink that will fetch our token from storage and append it to the headers.</p><p>Finally, we use concat to add the httpLink to our authLink and pass all of that to the ApolloClient. That’s hard to follow, code is easier to understand…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4345f53fab999a4233baed1ab9fa39d5/href">https://medium.com/media/4345f53fab999a4233baed1ab9fa39d5/href</a></iframe><p>This leaves us with…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*QX79NdYjnG7fTXggczk6PQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*CIXK9Uy8YYOrpTJ20sBXCA.gif" /></figure><p>I hope you found this series helpful! Let me know if there are other things you’re wanting to see in the realm of React Native + GraphQL.</p><p>Final Code:</p><p><a href="https://snack.expo.io/HJjWN6_0W">https://snack.expo.io/HJjWN6_0W</a></p><blockquote>My name is Spencer. I teach people to build 🔥 apps with React Native. Interested in more high quality tutorials? <a href="http://www.handlebarlabs.com/m/react-native-graphql/">Sign up for my email list</a>.</blockquote><h3>Additional Exercises</h3><p>Want to expand on this tutorial? How about…</p><ol><li>Checking the validity of a JWT before choosing which layout the user sees</li><li>Add some loading indicators to better handle the delay currently shown</li><li>Better handle errors</li></ol><blockquote>Did you find this helpful? Be sure to 👏 for it!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13ac8c362113" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-2-2-13ac8c362113">GraphQL Authentication with React Native &amp; Apollo [Part 2/2]</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL Authentication with React Native & Apollo [Part 1/2]]]></title>
            <link>https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-1-2-9613aacd80b3?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/9613aacd80b3</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Wed, 01 Nov 2017 14:34:41 GMT</pubDate>
            <atom:updated>2018-01-22T22:45:41.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fwe-6psYmeU2QkM9zVNkWQ.jpeg" /></figure><h4>Using Express, MongoDB, and JSON Web Tokens</h4><p>I’ve been playing with Apollo a lot lately and, as with nearly any app, I needed to add authentication to that app. I looked around but couldn’t find any posts specifically on the subject of authentication using React Native, GraphQL, and MongoDB — so that’s what we’ll be covering today.</p><p>In part one of this series you’ll learn how to configure the server (using GraphQL/Apollo, Mongo, Express, and JSON Web Tokens). In part two we’ll setup the React Native client to interact with it all.</p><p>The app we’ll be building is very simple, but will demonstrate the critical pieces of an authentication flow. It will have 3 screens:</p><ul><li>Login</li><li>Register</li><li>Log out</li></ul><p>Ready? Let’s go.</p><h3>Prefer Video?</h3><p>Prefer video tutorials? I made this tutorial into a video, which can be found below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_kYUzNVyj-0%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_kYUzNVyj-0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_kYUzNVyj-0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5e70010166aae72278b68694d9d865a/href">https://medium.com/media/d5e70010166aae72278b68694d9d865a/href</a></iframe><h3>Setup</h3><p>We’re going to use three tools throughout this, all free, all 100% browser based, some requiring sign up.</p><h4>Server</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6bm-OQtqOka99u-ZG37Cgw.png" /></figure><p>Since the whole point of this tutorial is to hook up GraphQL/Apollo and React Native we can leverage an incredible web-based tool, <a href="https://launchpad.graphql.com/new">Launchpad</a>.</p><p>This will go ahead and setup our server for us, set up GraphQL, and give us an endpoint to work with. When you’re ready to make it more serious you can easily export the entire express app, with all your existing work, and you’re off to the races!</p><p>I would suggest signing in/creating an account so you can save your work.</p><h4>Database</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dn0w4XIlg7VJ9Ou8MzA-Cw.png" /></figure><p>I don’t like setting up database. It’s a personal thing. It’s too serious for me. So I always offload the work to someone else. This time we’ll be using <a href="https://mlab.com/">mLab</a> to handle the Mongo database — they’ve got a free sandbox tier and that will be absolutely perfect for us.</p><p>You’ll need to sign up for this one.</p><blockquote>A note on databases: Don’t want to use Mongo? You can still use this tutorial, just use your preferred DB and modify the queriers to work with it.</blockquote><h4>React Native</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHC-bjM5Q9R2ANrxtma7Gw.png" /></figure><p>I’m going to be using <a href="https://snack.expo.io/">Snack by Expo</a>. It’s an incredible web-based way to build React Native apps. Once you’re done you can easily export it into your normal development flow, just like Launchpad. One suggestion I do have is to download the Expo app and use that as your development device, I find the experience to be better than when using the in-browser simulator.</p><p>I would suggest signing in/creating an account so you can save your work, though it’s not required.</p><p>Easiest setup in history? I’d say so.</p><h3>Configuring the Server</h3><p>The first thing we’ll do is configure our server on Apollo Launchpad. Here’s a simplified version of the server you can use to get started. If you’ve got a basic familiarity with GraphQL (which I’m assuming you do) you’ll pick up on this quickly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7df3e901fb14d6c9be21ce2c14bf8865/href">https://medium.com/media/7df3e901fb14d6c9be21ce2c14bf8865/href</a></iframe><p>In Launchpad you should now be able to query “hello” and get a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBRNy3kokiyIzzX-zJFL-A.png" /></figure><p>First thing we’ll do is setup all the necessary queries for our GraphQL endpoint. Given our basic feature spec the only query we need is one that will return a user. Just return a basic user object that has an _id and email for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b0590440df48e1bbaea12d30e97c430/href">https://medium.com/media/5b0590440df48e1bbaea12d30e97c430/href</a></iframe><p>Now let’s set up the necessary mutations, login and signup. These should each accept an email and password.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f62214b2607ec8fc5f0992d6b83dbec/href">https://medium.com/media/1f62214b2607ec8fc5f0992d6b83dbec/href</a></iframe><p>Go ahead and give it a try to make sure you don’t have any errors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ebc35c7d7ba67b085a6bcfe26052baf/href">https://medium.com/media/9ebc35c7d7ba67b085a6bcfe26052baf/href</a></iframe><h3>Connecting to the Database</h3><p>Once you’ve set up your account with <a href="https://mlab.com/">mLab</a> and created a new mongo db instance you should see a url along the lines of</p><pre>mongodb://&lt;dbuser&gt;:&lt;dbpassword&gt;<a href="http://twitter.com/ds121665">@ds121665</a>.mlab.com:21665/graphql-auth-demo-1</pre><p>you’ll also need to create a user for that database (with write permissions). Take that url and add it to our “secrets” as MONGO_URL in Launchpad. Make sure to swap out &lt;dbuser&gt; and &lt;dbpassword&gt; with the values of the user you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gyqhIDS6tJTGM7gmI9HAkg.png" /></figure><p>By adding the secret values here we can access them from our context function, which is where we’ll be establishing our mongo connection. This context function will be called each time a request is made to a GraphQL endpoint so we want to store a reference to our connection outside of the function (allowing us to only make the db connection request once). We’ll then return the mongo variable in context so that we access it in our resolver functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69e94f04a612045c2e0ed0ae1b107fa6/href">https://medium.com/media/69e94f04a612045c2e0ed0ae1b107fa6/href</a></iframe><p>Make sure you import { MongoClient } from &#39;mongodb&#39;; at the top of your file! Launchpad will automatically install it.</p><h4>Sign Up</h4><p>Now let’s access the database from the resolver functions… first signup. We’ll get a reference to a users collection and then check if a user with the given email address already exists.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f636155cde784ccf98bf61390cf73bbf/href">https://medium.com/media/f636155cde784ccf98bf61390cf73bbf/href</a></iframe><p>We can then insert the user document into the collection. I’ll be using bcrypt to hash the user’s password, because you should never store a plain text password in your database! Make sure you import the lib:</p><pre>import bcrypt from &#39;bcrypt&#39;;</pre><p>I’m going to be using async/await because it makes for easy to follow code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a078bffda3ff94bfc38f1943651b3a9/href">https://medium.com/media/6a078bffda3ff94bfc38f1943651b3a9/href</a></iframe><p>Go ahead and give it a shot in Launchpad</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47ded63d54e0e9b6501c5b30fb5c44b5/href">https://medium.com/media/47ded63d54e0e9b6501c5b30fb5c44b5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oPOeT_cdLlNF_uBNj4YoYg.png" /></figure><h4>Login</h4><p>The login mutation is very similar to the one we just put together.</p><p>First we’ll check if a user with that email address exists.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e4693f55093a41f435a1e2b74af266f/href">https://medium.com/media/3e4693f55093a41f435a1e2b74af266f/href</a></iframe><p>Then we’ll compare the password supplied and the password we have stored. If they match then return the user!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92507177c5b7f37c1c60a8c06482f329/href">https://medium.com/media/92507177c5b7f37c1c60a8c06482f329/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*2cRzaT85ZnPP-mnapJ5K_Q.gif" /></figure><p>So now we’ve got our sign in &amp; sign up mutations working, but that isn’t all! We don’t want to force the user to have to login with every request. Enter…</p><h3>JSON Web Tokens</h3><blockquote>JSON Web Token (JWT) is an open standard (<a href="https://tools.ietf.org/html/rfc7519">RFC 7519</a>) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the <strong>HMAC</strong> algorithm) or a public/private key pair using <strong>RSA</strong>.</blockquote><p>For us this means that we can generate a JWT and use that as a means of confidently identifying a user. The flow will work like this</p><ol><li>User logs in or signs up</li><li>The server returns a JWT</li><li>The client saves the JWT to their local storage (covered in part 2)</li><li>The JWT is passed with each request from client to server (on the Authorization header — covered in part 2)</li><li>The server uses the JWT to grab the user’s information and add it to context</li></ol><blockquote>A note on step 5: Since I wanted to keep this all browser based we need to do this manually. If you’ve got total control over the server though you can use <a href="https://www.npmjs.com/package/express-jwt">express-jwt</a> to do this automatically. This is a good way to learn what that module is doing though!</blockquote><h4>The Secret</h4><p>A JWT is signed with a secret value. We’ll want to come up with one and add that to the “Secrets” in Launchpad, like we did MONGO_URL. I’m storing it as JWT_SECRET with a value of super-secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8z9202Dp3Whe9eIaiCpD0Q.png" /></figure><p>Now, using that secret we’ll want to generate a new JWT and return it on the user object when they successfully login or sign up. First I’ll add jwt to the User type in our type definitions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b3236a46045e1151db19b1c4d0806c1/href">https://medium.com/media/9b3236a46045e1151db19b1c4d0806c1/href</a></iframe><p>Make sure you add import jwt from &#39;jsonwebtoken&#39;; to the top of your file.</p><h4>Generating the Token</h4><p>Then, upon successful login, I’ll create a JWT. We’re passing the user’s id as part of the payload and secrets is coming from context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af7c774042a9d23ba58ecde3c293fa03/href">https://medium.com/media/af7c774042a9d23ba58ecde3c293fa03/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-1mtMJj87VDBP_Fa7Q-cA.png" /></figure><p>We’ll do the same for sign up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9c2ef7985161a56dc7a3c4b3b45352f/href">https://medium.com/media/c9c2ef7985161a56dc7a3c4b3b45352f/href</a></iframe><h4>Adding the Current User to Context</h4><p>Finally (for this part at least) we need to add the current user to context.</p><p>Remember, if you’re not using Launchpad you can use express-jwt to do this automatically. I also need to note that I’m basing this function a bit off of <a href="https://launchpad.graphql.com/n4xk8xm87">this launchpad</a> which does the same thing but for the Auth0 service.</p><p>First, create a new function called getUser and check if we’ve got a potentially valid authorization token in the header.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fbacd8fe47e932a324a2ade4f2f4527/href">https://medium.com/media/4fbacd8fe47e932a324a2ade4f2f4527/href</a></iframe><p>Then we’ll try to verify the token that was passed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e032c74e5c3b91088c5ac14e1803c03c/href">https://medium.com/media/e032c74e5c3b91088c5ac14e1803c03c/href</a></iframe><p>Then we’ll attempt to fetch the user from our database using the _id that we put into the jwt payload initially. ObjectId is coming from the mongdb module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e032c74e5c3b91088c5ac14e1803c03c/href">https://medium.com/media/e032c74e5c3b91088c5ac14e1803c03c/href</a></iframe><p>Finally, let’s go ahead and call this getUser function from the context function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59860a6567f2b2c51d9a1905492839ab/href">https://medium.com/media/59860a6567f2b2c51d9a1905492839ab/href</a></iframe><p>We can also update the currentUser query to return the user from context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/341fd172990b2235cceddda96d5731fe/href">https://medium.com/media/341fd172990b2235cceddda96d5731fe/href</a></iframe><p>Let’s go ahead and check this out…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KagLvLnq7dS_pxWcgXzIBA.gif" /></figure><p>And there you have it! Runnable source code is available below</p><p><a href="https://launchpad.graphql.com/xnmjwwlpml">Apollo Launchpad</a></p><p>This was just the first part of this series, in part 2 we’ll connect our React Native app to it.</p><p>Part 2 is available here:</p><p><a href="https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-2-2-13ac8c362113">GraphQL Authentication with React Native &amp; Apollo [Part 2/2]</a></p><blockquote>My name is Spencer. I teach people to build 🔥 apps with React Native. Interested in more high quality tutorials? <a href="http://www.handlebarlabs.com/m/react-native-graphql/">Sign up for my email list</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9613aacd80b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/graphql-authentication-with-react-native-apollo-part-1-2-9613aacd80b3">GraphQL Authentication with React Native &amp; Apollo [Part 1/2]</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Redux to Manage React Navigation State]]></title>
            <link>https://medium.com/handlebar-labs/use-redux-to-manage-react-navigation-state-b6d639497143?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/b6d639497143</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-navigation]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Wed, 14 Jun 2017 14:14:57 GMT</pubDate>
            <atom:updated>2017-06-14T14:14:57.358Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_cTm9CCz2TqSs6__KQAGg.jpeg" /></figure><p>If you’ve ever wanted to know how to store the state from React Navigation in Redux and didn’t understand the <a href="https://reactnavigation.org/docs/guides/redux">guide in the docs</a> — look no further! I put together a quick video on how you can do so.</p><p>The guide is great but sometimes it’s helpful to see someone walking through the process. That’s what this video covers — I definitely suggest you read the guide as well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJT9Jah5WBr4%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJT9Jah5WBr4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJT9Jah5WBr4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2c310e2942eb5cc281730e7771a81c9/href">https://medium.com/media/a2c310e2942eb5cc281730e7771a81c9/href</a></iframe><blockquote>If you’re interested in building the app I use to demonstrate this <a href="http://learn.handlebarlabs.com/p/react-native-basics-build-a-currency-converter">check out my free React Native course</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d639497143" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/use-redux-to-manage-react-navigation-state-b6d639497143">Use Redux to Manage React Navigation State</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native + Meteor: react-native-meteor vs. meteor-client-bundler]]></title>
            <link>https://medium.com/handlebar-labs/react-native-meteor-react-native-meteor-vs-meteor-client-bundler-f7597442ed0?source=rss----2b0347ae7102---4</link>
            <guid isPermaLink="false">https://medium.com/p/f7597442ed0</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[meteorjs]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Spencer Carli]]></dc:creator>
            <pubDate>Wed, 10 May 2017 13:36:03 GMT</pubDate>
            <atom:updated>2017-05-10T13:36:03.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7vCpGPYuKhy9Xo7ecX14Q.jpeg" /></figure><p>If you’ve spent any time looking into building an app with React Native and Meteor you’ve likely come across the package <a href="https://github.com/inProgress-team/react-native-meteor">react-native-meteor</a>. You may have also come across <a href="https://github.com/Urigo/meteor-client-bundler">meteor-client-bundler</a> which is a newer entry in the game.</p><p>So what are they?</p><p>Each package is designed to allow you to easily connect to and work with a Meteor server, via DDP, from a client that isn’t integrated with the Meteor build tool.</p><p>They do this in different ways, each with benefits and drawbacks.</p><h3><a href="https://github.com/inProgress-team/react-native-meteor">react-native-meteor</a></h3><p>This package integrates within your React Native app and is designed specifically for React Native. The goal is to provide a one-to-one match of the client side Meteor functionality. Having built multiple apps on this package I can tell you it does this well.</p><p>This project is completely independent of Meteor — it’s just aware of the DDP protocol exposed by Meteor and makes easy to use wrappers around DDP to access it. That means it depends on third party code to do some things (minimongo, tracker, etc).</p><h4>Benefits</h4><ul><li>This is a battle tested package. I’ve used it on multiple React Native + Meteor projects and know numerous other who have done the same.</li><li>API closely matches that of the Meteor client API meaning that it’s easy to use.</li><li>Just about everything works and works well. Not much left to be desired.</li><li>Get up and running quickly. Minimal configuration. Once installed from NPM you can get things going in no time.</li><li>Simple. I love simple.</li><li><a href="http://reactnativemeteor.com/">Great learning resources</a>. 😄</li></ul><h4>Drawbacks</h4><ul><li>API is slightly different than that of the “real” Meteor client. There are some small differences you need to be aware of, but they’re clearly documented</li><li>Dependence on third party packages. react-native-meteor uses some third party packages that don’t have the same kind of support/battle testing that it does on Meteor. They work well but it’s something to be aware of.</li><li>OAuth is going to be a pain.</li><li>Maintenance. This is an open source package where people are maintaining it on the side.</li></ul><h4>Getting Started</h4><p>If you’re interested in getting up and running with a React Native + Meteor stack that uses react-native-meteor check out the <a href="https://github.com/spencercarli/react-native-meteor-boilerplate">boilerplate</a> I’ve put together.</p><blockquote>Thank you to everyone that has made this package a reality and continues to put the time into maintaining it. #ThankOSSMaintainers</blockquote><h3><a href="https://github.com/Urigo/meteor-client-bundler">meteor-client-bundler</a></h3><p>Unlike react-native-meteor this package is designed to work for any client — it was actually built when getting an <a href="https://github.com/Urigo/Ionic2CLI-Meteor-WhatsApp">Ionic app to work with Meteor</a>.</p><p>It also works in a different way — it’s a command line tool that will bundle the Meteor client code and put it into your React Native project rather than being a package that simply “speaks” DDP to communicate with a Meteor server. So whenever you change something in your Meteor app you’ll want to re-bundle the client side code.</p><h4>Benefits</h4><ul><li>Takes the actual client side Meteor code and injects it into your React Native app making sure you’re running exactly what’s on the Meteor server.</li><li>Use the “real” packages coming from Meteor.</li></ul><h4>Drawbacks</h4><ul><li>Potential mismatch of code injected between what’s running on the Meteor server and what’s on your user’s app.</li><li>Dependence on the DOM. There is some work in progress to get things going out of the box but it will take time. There are third-party solutions to get it running today.</li><li>OAuth is going to be a pain.</li><li>Setup can be a bit trickier, at least it was for me.</li><li>Maintenance. This is an open source package where people are maintaining it on the side.</li></ul><h4>Getting Started</h4><p>To get up and running with a React Native + Meteor stack using meteor-client-bundler check out <a href="https://github.com/DAB0mB/ReactNativeMeteorBoilerplate">this boilerplate</a>.</p><blockquote>Thank you to everyone that has made this package a reality and continues to put the time into maintaining it. #ThankOSSMaintainers</blockquote><h3>In Conclusion</h3><p>I think both are solid solutions. They approach the problem in different ways and they’ve each got their benefits and drawbacks. Nothing is going to be perfect so weigh the pros and cons, make a decision, and when you run into an issue contribute back to the project.</p><p>If neither solution works for you you can always <a href="https://github.com/oortcloud/node-ddp-client">manage the ddp connection directly</a>!</p><p>If you’re interested in a course on building a location based app using the React Native + Meteor stack check out my course <a href="http://reactnativemeteor.com/"><em>Learn React Native + Meteor</em></a><em> </em>(new lower prices!). We cover usage of react-native-meteor in the course but also have a great community you can be a part of and discuss the possibility of using meteor-client-bundler instead.</p><p>If you’ve got questions about the course shoot me an email spencer at handlebarlabs.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7597442ed0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/handlebar-labs/react-native-meteor-react-native-meteor-vs-meteor-client-bundler-f7597442ed0">React Native + Meteor: react-native-meteor vs. meteor-client-bundler</a> was originally published in <a href="https://medium.com/handlebar-labs">Handlebar Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>