<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marco Lanaro on Medium]]></title>
        <description><![CDATA[Stories by Marco Lanaro on Medium]]></description>
        <link>https://medium.com/@marcolanaro?source=rss-283325c2eb49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gefsl6nYVy-YXbCIeXaF3A.jpeg</url>
            <title>Stories by Marco Lanaro on Medium</title>
            <link>https://medium.com/@marcolanaro?source=rss-283325c2eb49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:07:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcolanaro/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Use Tensorflow DNNClassifier estimator to classify MNIST dataset]]></title>
            <link>https://codeburst.io/use-tensorflow-dnnclassifier-estimator-to-classify-mnist-dataset-a7222bf9f940?source=rss-283325c2eb49------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7222bf9f940</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mnist]]></category>
            <dc:creator><![CDATA[Marco Lanaro]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 17:09:27 GMT</pubDate>
            <atom:updated>2018-01-07T17:45:04.963Z</atom:updated>
            <content:encoded><![CDATA[<p>If like me you have followed <a href="https://www.tensorflow.org/get_started/mnist/pros">Deep MNIST for Experts</a> guide and the quickstart on how to use <a href="https://www.tensorflow.org/get_started/estimator">estimators in tensorflow</a>, you probably want to take a step forward. Classify MNIST dataset training a deep neural network [DNN] with estimators. In the following link you can find the <a href="https://www.tensorflow.org/programmers_guide/estimators">advantages on using estimators</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*9Mjoc_J0JR294YwHGXwCeg.jpeg" /><figcaption>MNIST dataset</figcaption></figure><h4>Read the dataset</h4><p>The first thing you have to change from your <a href="https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/examples/tutorials/mnist/mnist_deep.py">initial implementation</a> is the read statement of MNIST dataset. You need to change:</p><pre>mnist = input_data.read_data_sets(‘MNIST_data’, one_hot=True)</pre><p>Into:</p><pre>mnist = input_data.read_data_sets(‘MNIST_data’)</pre><p>The reason is that <em>labels</em> need to be a tensor with values from the vocabulary, i.e. [7, 2, …] when the first 2 images represent respectively 7 and 2. The option <em>one_hot=True</em> deal with one-hot tensor: 10-dimensional vectors indicating which digit class (zero through nine) the corresponding MNIST image belongs to. The 2 previous images would have been represented like [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], …].</p><p>DNNClassifier, the estimator we are going to use, expects a tensor matching the logits. In the scenario of one-hot tensor, the script would have boomed out with the following error:</p><blockquote>ValueError: Mismatched label shape. Classifier configured with n_classes=1. Received 10. Suggested Fix: check your n_classes argument to the estimator and/or the shape of your label.</blockquote><h4>Specify the features</h4><p>MNIST images have shape 28px x 28px, so we can define one feature with shape [28, 28]:</p><pre>feature_columns = [tf.feature_column.numeric_column(“x”, shape=[28, 28])]</pre><h4>Build a two layer DNN classifier</h4><p>As described in the quickstar guide, the signature of the classifier is pretty simple. Follow my configuration:</p><pre>classifier = tf.estimator.DNNClassifier(<br> feature_columns=feature_columns,<br> hidden_units=[256, 32],<br> optimizer=tf.train.AdamOptimizer(1e-4),<br> n_classes=10,<br> dropout=0.1,<br> model_dir=”./tmp/mnist_model”<br>)</pre><h4>Define the training inputs</h4><p>As said before, the classifier expect logits from the 10 classes that define the output. For this reason we have to cast the labels to <em>int32</em> types.</p><p>Let’s define the input function:</p><pre>def input(dataset):<br> return dataset.images, dataset.labels.astype(np.int32)</pre><p>And consume if in the training input:</p><pre>train_input_fn = tf.estimator.inputs.numpy_input_fn(<br> x={“x”: input(mnist.train)[0]},<br> y=input(mnist.train)[1],<br> num_epochs=None,<br> batch_size=50,<br> shuffle=True<br>)</pre><p>Without this casting operation, the script would have boomed out with the following error:</p><blockquote>TypeError: Value passed to parameter ‘labels’ has DataType uint8 not in list of allowed values: int32, int64</blockquote><h4>Training</h4><p>The training operation is simple as:</p><pre>classifier.train(input_fn=train_input_fn, steps=100000)</pre><h4>Define the test inputs</h4><p>This definition of the test input is similar to the training input:</p><pre>test_input_fn = tf.estimator.inputs.numpy_input_fn(<br> x={“x”: input(mnist.test)[0]},<br> y=input(mnist.test)[1],<br> num_epochs=1,<br> shuffle=False<br>)</pre><h4>Evaluate accuracy</h4><p>The <em>evaluate</em> method of the classifier need to receive in input the test input. It will output an object containing the accuracy obtained. With the current implementation it’s about 98.4%.</p><pre>accuracy_score = classifier.evaluate(input_fn=test_input_fn)[“accuracy”]<br>print(“\nTest Accuracy: {0:f}%\n”.format(accuracy_score*100))</pre><h3>Fully implemented classifier</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea6482e2cbcbc7c104cc6f5ce18b80b5/href">https://medium.com/media/ea6482e2cbcbc7c104cc6f5ce18b80b5/href</a></iframe><h3>Conclusion</h3><p>In this article you have learnt hot to use tensorflow DNNClassifier estimator to classify MNIST dataset.</p><p>The important understanding that comes from this article is the difference between one-hot tensor and dense tensor. We saw that DNNClassifier works with dense tensor and require integer values specifying the class index.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*70RN67LFNxtN8ynIxVK4OQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7222bf9f940" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/use-tensorflow-dnnclassifier-estimator-to-classify-mnist-dataset-a7222bf9f940">Use Tensorflow DNNClassifier estimator to classify MNIST dataset</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manage analytics actions in React]]></title>
            <link>https://medium.com/trainline/manage-analytics-actions-in-react-67fae61495de?source=rss-283325c2eb49------2</link>
            <guid isPermaLink="false">https://medium.com/p/67fae61495de</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[adobe]]></category>
            <dc:creator><![CDATA[Marco Lanaro]]></dc:creator>
            <pubDate>Wed, 05 Jul 2017 14:57:46 GMT</pubDate>
            <atom:updated>2017-07-05T15:34:51.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BkGxgg7R_FQFBia15dxGdQ.jpeg" /></figure><blockquote>Nosce te Ipsum</blockquote><p>Know thyself is a Latin aphorism that contains a double meaning. You should recognise your best skills, your strength and what you can achieve. You should also recognise your limitations because you’re human, or in our case, a frontend developer.</p><p>As a frontend developer we all love UI, UX and animations: the things we can see and play with. Unfortunately we also need to think about something less tangible: analytics.</p><p>Let’s say we create what we think is the best experience for our users, how can we prove it? How can we know how the user responded to a new feature we are adding to our awesome app? You want to know what your customers are looking for, who they are, how they behave and how they are segmented. In the back of your mind you should always think about how each page of your site is performing and affecting the funnel to conversion.</p><p>As developers we must always strive to provide evidence that what we’re driving towards is working by deriving answers from user interactions.</p><p>I don’t want to waste your time with Latin aphorisms or analytics requirements, so the only thing you have to know is that at Trainline we use Adobe Marketing Cloud and specifically, Dynamic Tag Management [DTM] to collect our analytics data. The only thing that a developer should know is how to dispatch custom browser events. Every event will be paired with some payload called tagData. DTM will listen to the event, collect the payload and manage analytics integration.</p><p>In this way you can decouple the analytics team and the development team resulting in a more agile process and more testable code. I really liked the following quote from Jeff Chasin in his <a href="https://blogs.adobe.com/digitalmarketing/analytics/dynamic-tag-management-overnight-test/">post</a>:</p><blockquote><em>With DTM, I can now avoid that back and forth with the development team and use the time I save to conduct more strategic work and more comprehensive tracking.</em></blockquote><p>I also suggest reading more about <a href="https://blogs.adobe.com/digitalmarketing/analytics/dynamic-tag-management-helps-analytics-teams-beat-clock/">Adobe DTM</a> to better understand our rationale for using this analytics solution.</p><h3>Our technical stack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*d525hVvyFhPM6S6_m-ZMmw.gif" /></figure><p>We are a frontend team that owns the booking flow pages. The website is implemented in TypeScript using React and Redux for state management with Redux Observable middleware (RxJS) being used to handle asynchronous behaviour and side effects.</p><h3>Analytics events and side effects</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*VQ68cgMqeBrap9HGFSZBFA.gif" /></figure><p>Firstly, analytics events are side effects.</p><p>An analytic event cannot be implemented with a <a href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-pure-function-d1c076bec976">pure function</a> due to a reliance on an external library that in turn triggers remote calls to an analytics server.</p><p>Instead, side effects can be encapsulated to ensure that our application code contains as few impure functions as possible.</p><p>The best approach we have found is to use redux-observable to generate analytics actions which are heard by custom middleware which in turn executes the side effect.</p><p>First define an analytics action creator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1eb465ce6806261dca74b9173a1117f2/href">https://medium.com/media/1eb465ce6806261dca74b9173a1117f2/href</a></iframe><p>Then handle the analytics action (below is a simplified add item to basket f):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8153d35de7882016dd1a52920e87cdc/href">https://medium.com/media/d8153d35de7882016dd1a52920e87cdc/href</a></iframe><p>This avoids causing side effects in the application code when triggering a DTM event — the redux architecture allows middleware to encapsulate this logic elsewhere.</p><h3>How to trigger the analytics event</h3><p>In a react web application, there are multiple ways to trigger an analytics event with functional requirements falling into two categories:</p><ol><li>User interaction events, e.g. clicking on a button (usually fairly simple to resolve by triggering the function created by analyticsActionCreator in an epic)</li><li>Page load events</li></ol><h4>Page loaded event</h4><p>We are implementing a single page app which means the application loads once, with page changes being handled on the client side, avoiding the disjointed fracture of a full page refresh.</p><p>Because the page loaded event is strictly related to routing triggering it can be done in two ways:</p><ol><li>Hooking directly into the router</li><li>Listening to changes history changes within an epic</li></ol><h4>Hooks into the router</h4><p>Define onEnter and onChange route handlers, passing on the dispatch function and then dispatch the action that will trigger your analytics epic:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ba033f65a3c9a69c33579a261e1eeda/href">https://medium.com/media/6ba033f65a3c9a69c33579a261e1eeda/href</a></iframe><h4>Let an epic listen to the history</h4><p>Another solution contains a little bit more magic, but ends up being less imperative and more functional. Define an epic that triggers your analytics action when the history changes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0b848d20e77d266734e9972ada13aa3/href">https://medium.com/media/b0b848d20e77d266734e9972ada13aa3/href</a></iframe><p>The downside of this approach is that <em>isMyPageRoute</em> needs to inspect the history object and use regex to guess which page is now being rendered.</p><h4>Some thoughts</h4><p>If redux best practices are adopted:</p><ul><li>State is fully normalised</li><li>Reducers are the single source of truth</li><li>Selectors are atomic and composable</li></ul><p>We are able to have a deterministic view renderer. Our analytics actions should also be deterministic and driven by the page loaded events from router/epics.</p><p>Unfortunately, in the real world this is not always true. Sometimes, complex scenarios arise preventing the clean implementations documented above:</p><ol><li>A route change occurs</li><li>A side effect is dispatched to fetch some data</li><li>Depending on the content of the data returned, the query may again be updated (e.g. to reflect a default selection) which will in turn trigger another fetch unless it is guarded against</li></ol><p>Multiple layers of side effects tend to create complex race condition-related bugs. Additionally they add cognitive overhead by necessitating delicate logic to govern when actions should be dispatched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*-Pnowx_3Gek2auRA5eGyuA.gif" /></figure><h4>This isn’t great, let’s take a step back</h4><p>At this point two impulses materialize:</p><ol><li>Push back on requirements</li><li>Stop thinking about routing</li></ol><p>What we can’t do is push back on the requirements. But what we can do is stop thinking about routing by utilising the React Component lifecycle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38e9569e083421aa1ac4d11f5f3187e0/href">https://medium.com/media/38e9569e083421aa1ac4d11f5f3187e0/href</a></iframe><p>The analytics action is encapsulated within the onViewRendered action creator. Of course this should only be triggered at specific points:</p><ol><li>On first render</li><li>Every time the user performs an action that triggers data to be fetched that entails a significant re-render of the page</li></ol><p>Another advantage of this approach is that we have more control during more complex rendering scenarios. For instance if the page is animated and analytics events should only be sent when one or more animations complete, since we are driving this from within the component, precise control of when triggers occur becomes relatively simple.</p><p>Now you can easily generate your own <a href="https://facebook.github.io/react/docs/higher-order-components.html">high order component</a> that manages the lifecycle of your page analytics component. In this way you don’t have to hook in to <em>componentWillUpdate</em> every time you have to implement something like that. You can just wrap your page component in a factory, passing down a configuration object, i.e. one containing an <em>itMakesSense</em> predicate and <em>onViewRender</em> action creator.</p><h3>The middleware</h3><p>I would suggest you look into the redux middleware documentation to understand how to write your own middleware, but the basic idea is that if the action has a specific type (or has a specific meta key) the side effect should be generated and only after this has occurred, do we pass the action down to the next step of the middleware chain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b54539a5da3571165679b535efa05b6/href">https://medium.com/media/1b54539a5da3571165679b535efa05b6/href</a></iframe><h3>Async loading of the analytics library</h3><p>At this point you might think that everything looks too simple and that some complexity is being hidden. You are correct! There’s one particularly troublesome beast still to slay.</p><p>Before dispatching your first custom event, the analytics library(ies) needs to have been fully downloaded, parsed and executed. That requires a lot of time to be completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NbtbSWe7DH_oyEneA1brlg.gif" /></figure><p>Someone might think they’re being smart by importing the library, e.g. Satellite or Google Analytics, at the top of the page and then render the application as soon as the library is ready in the DOM:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/539f5b7eb745b846acb02b3863aed122/href">https://medium.com/media/539f5b7eb745b846acb02b3863aed122/href</a></iframe><p>This is the perfect example on how not to architect a web page. Page rendering is now being blocked twice:</p><ol><li>While the synchronous analytics library script tag is downloading, preventing the execution of anything below</li><li>While the React application is prevented from being rendered waiting for the “ready” event to be dispatched by Satellite</li></ol><p>A better approach is to defer the analytics events until external dependencies have loaded, but still allow the rendering of the React application. As soon as the analytics library is ready the replay of actions can occur.</p><p>The following is not production code, but (a simplified version of) the track function could look something like this:</p><p>And the deferred array should be the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d0d1b7e96e012a2577544da05ce9b21/href">https://medium.com/media/5d0d1b7e96e012a2577544da05ce9b21/href</a></iframe><h3>Conclusion</h3><p>In this article I showed you where to find some good resources about Adobe Tag Manager and why you should use it.</p><p>Later on we went through the process of thinking about how to dispatch a DTM event through a react/redux application.</p><p>We tried to attack the <em>page loaded</em> requirement in different ways. As always, there is no best solution: it depends on the complexity of your application, on what you want to achieve and on what you feel is correct for your developer experience (where your team prefers to create cognitive overhead).</p><p>We also learned how to defer analytics action so as not to block the rendering of the application and improve the perceived performance of the page.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67fae61495de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trainline/manage-analytics-actions-in-react-67fae61495de">Manage analytics actions in React</a> was originally published in <a href="https://medium.com/trainline">The Trainline Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Payment request API with React]]></title>
            <link>https://codeburst.io/payment-request-api-with-react-b47e36efcec5?source=rss-283325c2eb49------2</link>
            <guid isPermaLink="false">https://medium.com/p/b47e36efcec5</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[credit-cards]]></category>
            <category><![CDATA[payments]]></category>
            <dc:creator><![CDATA[Marco Lanaro]]></dc:creator>
            <pubDate>Thu, 29 Jun 2017 13:30:44 GMT</pubDate>
            <atom:updated>2017-06-29T16:40:15.595Z</atom:updated>
            <content:encoded><![CDATA[<p>As a front end developer passionate about e-commerce platforms I had the chance to work on the development of a mobile booking flow and I soon realised that it’s very difficult to create a low friction experience with high engagement and easy to use workflow.</p><p>Reducing friction and making our user’s life easier when it’s time to make a purchase is fundamental. The checkout process is probably the most stressful step for our users.</p><h4>The problem</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*p5BvmJGvlKZ_NtgmB5MssQ.gif" /></figure><p>People usually don’t enjoy the process of buying something on the web using their mobile devices.</p><p>They do not remember all 16 digits, cvv, expiration of their credit/debit card. Then the users need to add their contact details, billing/shipping address.</p><p>They do not trust the website: it does not matter if the website has the green locker on the navigation bar; the user experience and the user interface is always different because every website implements a different solution to resolve the same problem.</p><p>On top of this, users need to add the same information using different keyboards, dealing with fat fingers, moving through multi page forms. It’s a large set of information, always the same, tedious and repetitive.</p><h4>Statistics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xgNSme8N8VoDVrkeDVXsDA.gif" /></figure><p>If we try to compare the desktop web site and the mobile website of a product I’ve worked on, we find a very interesting situation. Despite the mobile traffic is continuously increasing, the conversion on mobile web devices is pretty low. Now, I’m not saying that the mobile web product is badly engineered. I’m also not saying that we should compare the users base. People probably use the two products in two different ways and they expect something different.</p><p>I can probably give you the following rough statistic about a product I have worked on in the past. The mobile web traffic is <strong>30% more</strong> of the desktop web traffic. The mobile web conversion is <strong>60% less</strong> of the desktop web conversion.</p><p>If we now try to compare the native apps (ios and android) with mobile web, we can see something very interesting. On mobile web, the step conversion between the result page and the checkout page is the same as a native app, i.e. ~30%. Despite this, the step conversion between checkout page and payment confirmation is half, i.e. <strong>30% on native app</strong> versus <strong>15% on mobile web</strong>.</p><h4>Other requirements</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*2O0wIYp7R0hnozGpX2pyjg.gif" /></figure><p>On top of all this, as developers we unfortunately have to deal with some business requirements that are not always simple to meet:</p><ul><li>guess the card type as soon as you start type the number</li><li>validating the number</li><li>guess when the number is complete so to jump the focus of the user on the next field</li><li>add spaces between digits to change the syntax depending on the type of the number</li></ul><p>These require always being up to date with new cards that banks are continuously releasing. Imagine also providing OCR functionality with the device’s camera.</p><blockquote>Save the world from tedious checkout forms with <strong>Payment Request API! </strong>💳</blockquote><h4>Payment Request API is not</h4><p>Payment Request API does not integrate with a payment processor; it’s not going to replace Braintree. It’s not a new payment method, you will still deal with cards payment, Paypal, Android/Samsung pay, AliPay. It’s not a finalised standard: at this moment in time we have a <a href="https://www.w3.org/TR/payment-request/">working draft</a> already <a href="https://caniuse.com/#feat=payment-request">implemented by 30% of the browser in the market</a>. It’s not supported by Safari because the vendor (Apple) has implemented their own specific standard and payment method, i.e. ApplePay.</p><h4>Payment Request API is</h4><p>It’s an open standard already available in Chrome, Chrome for Android, Microsoft Edge and Opera. This standard allows users to pay in the way they want to pay and do it quickly and efficiently.</p><p>The browser plays a middleware role to help facilitate checkout at the highest friction point. It helps exchange sensitive information between the merchant, the user and the payment provider in a secure and sandboxed way.</p><p>It’s a native user experience. It will look and feel as any other native application. Despite being a native widget controlled by the browser, the merchant’s name, icon and url are visible, signifying safety through brand recognition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ON7_AJZDDNOwiSekXKhFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*270NWwW95mQsLpFpnBtjCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87LMTDJ4cfyeLVu6x57HVQ.png" /><figcaption>Chrome Mobile user experience of Payment Request API</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZ44AD2hLu5QkeBcyqknfA.png" /><figcaption>Chrome Desktop user experience of Payment Request API</figcaption></figure><h3>A React high order component for it</h3><p>React is great, I love the community and the good amount of library you can find out there. Despite this, sometimes it’s difficult to find a great solution for a problem you are facing. That’s the reason why I have decided to write a <a href="https://facebook.github.io/react/docs/higher-order-components.html">high order component</a> [HOC] around this API. With a HOC you can encapsulate a powerful behaviour providing a cleaner interface and a easier way to consume a composable API.</p><p>On Github:</p><p><a href="https://github.com/marcolanaro/react-payment-request-api">marcolanaro/react-payment-request-api</a></p><p>On NPM:</p><p><a href="https://www.npmjs.com/package/react-payment-request-api">react-payment-request-api</a></p><h4>Let’s get started</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*hyqJzpqML8_OsEir6KCahw.gif" /></figure><p>You can write your dumb UI component like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b22f467a23a0ad63e1fd4f7ae12fdda/href">https://medium.com/media/7b22f467a23a0ad63e1fd4f7ae12fdda/href</a></iframe><p>And consume it as follow:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36d9db5026d488875c13737c5467840b/href">https://medium.com/media/36d9db5026d488875c13737c5467840b/href</a></iframe><p>As you can see, the HOC consume the config prop to enhance the interface and the behaviour of the dumb component. The HOC inject into the UI component three props: <em>isSupported</em>, <em>show</em>, <em>abort</em>. All the other properties provided by the parent component are spread down into the UI component, e.g. <em>style</em>.</p><p><em>isSupported</em> is a boolean property that allow you to drive a different UI if the browser does not support the API.</p><p><em>show</em> is the handler you have to attach to user action when you want to initialise and show the browser widget</p><p><em>abort</em> is the handler you have to execute if you want to abort the process and close the widget prematurely.</p><p><strong>Configuration</strong></p><p>The <em>config</em> property is an object that describe which data should be driven in the browser native widget and the handlers that allow us to control some behaviours.</p><p>Before diving into the configuration I really suggest you to look into the native API documentation written by <a href="https://twitter.com/gauntface">Matt Gaunt</a> and <a href="https://twitter.com/agektmr">Eiji Kitamura</a>.</p><p><a href="https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/deep-dive-into-payment-request">Deep Dive into the Payment Request API | Web | Google Developers</a></p><p>Now that you have an overview on how the API works, I suggest you to look into the <a href="https://github.com/marcolanaro/react-payment-request-api#api">documentation of the config property</a>.</p><h3>Conclusion</h3><p>In this article you have learnt why you should decrease the friction of the user providing a simple to use experience and leverage the browser when it’s possible to behave like a native app. Given the fact that the checkout of a booking flow is one of the worst experiences a user could face on mobile web, we all should start implementing Payment Request in our applications.</p><p>You have also learnt how to consume a React high order component to implement the Payment Request API with few simple steps.</p><p>I really suggest you to have a look in the W3C documentation; despite the API is already stable in about 30% of the browsers, the standard is still a work in progress draft:</p><p><a href="https://www.w3.org/TR/payment-request/">Payment Request API</a></p><p>Now you are ready to decrease the friction of your customers improving the user experience and increasing conversion. So enjoy, consume high order components and make the money fly 💸.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*4NqyVE_01n9eiCSIvi1o1Q.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b47e36efcec5" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/payment-request-api-with-react-b47e36efcec5">Payment request API with React</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>