<?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 Antoine Sauvage on Medium]]></title>
        <description><![CDATA[Stories by Antoine Sauvage on Medium]]></description>
        <link>https://medium.com/@antoine_52391?source=rss-cd64a2df4fcd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I-pg3Z_ysvdXo4DUwucJlw.jpeg</url>
            <title>Stories by Antoine Sauvage on Medium</title>
            <link>https://medium.com/@antoine_52391?source=rss-cd64a2df4fcd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:53:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antoine_52391/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[React: Good Props/Bad Props]]></title>
            <link>https://medium.com/ovrsea/react-good-props-bad-props-861ee99ff90e?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/861ee99ff90e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[props]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 12:55:52 GMT</pubDate>
            <atom:updated>2022-10-31T15:39:07.540Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever written components with props names such as “isFirstElement”, “fromAuthenticationScreen”, “v2”, “adminVersion”? I did, and I regretted it months later when I had to add a new functionality ❌</p><p>In presentational components, those names can really be considered as huge warning/code smell, and this is what this article is about 💻</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/524f51b4a1b0b756cd46039cc8d8ba7c/href">https://medium.com/media/524f51b4a1b0b756cd46039cc8d8ba7c/href</a></iframe><h3>TL;DR</h3><p>There are two kinds of props in React: good props and bad props</p><p><strong>Your props should describe your component capabilities, not your component context</strong></p><h3>The Good Props/Bad Props rule</h3><h4>At the beginning: The Open-closed Principle</h4><p>Whether you follow or not the Container/Presentational dichotomy (<a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0</a>) or if you have your business logic encapsulated in hooks, you might still have <em>presentational</em> components in your codebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*_bl3cLAStBqYqmRI" /><figcaption>React Router. Credits to <a href="https://unsplash.com/@flowforfrank">Ferenc Almasi</a> (Unsplash)</figcaption></figure><p>Ideally, those components must be <strong>reusable</strong>, in the sense that if you want to extend them to do something very similar, you should be able to do it easily, <strong>without modifying them</strong>.</p><p>This is what is called the <strong>Open-Closed principle </strong>(<a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle">https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle</a>), at least in its functional version.</p><h4><strong>Choosing good props</strong></h4><p>Being able to extend a component without modifying it has a lot to do with choosing the right props in the beginning, as we will see in our example.</p><p>I always struggle when I create the first version of a component. So I started to follow a rule of thumb:</p><blockquote><strong>Props should describe what a component does, not what a component is</strong></blockquote><p>And it works!</p><h3>Example</h3><p>Let’s take the example of a to-do list app. This app shows a list of items, where the first item is colored in grey, and there is a divider between all the items. Below is a good version and a bad version of the Item component:</p><p><strong>The bad version — isFirstItem</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/524f51b4a1b0b756cd46039cc8d8ba7c/href">https://medium.com/media/524f51b4a1b0b756cd46039cc8d8ba7c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2360f200c356d5d36759c70642b504b9/href">https://medium.com/media/2360f200c356d5d36759c70642b504b9/href</a></iframe><p><strong>The good version — showDivider</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0e6997765d6ed4afe21c05908c77367/href">https://medium.com/media/d0e6997765d6ed4afe21c05908c77367/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61369b25008e28bcd1e66a68d809d7ae/href">https://medium.com/media/61369b25008e28bcd1e66a68d809d7ae/href</a></iframe><p>At first, the “isFirstItem” approach looks a bit better: it’s shorter and it enforces a consistent style across our different lists. But it has drawbacks :</p><ul><li>if we want to reuse our component somewhere else, it can be a bit tricky (1)</li><li>we coupled the color and the divider of the item (2)</li></ul><p>To illustrate 1 and 2, let’s imagine that we are very proud of our Item component and we want to reuse it to show an item that we selected somewhere else on our app, with grey color and no divider. The calls would look like this :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08d01a6455a17a07f147f369053485da/href">https://medium.com/media/08d01a6455a17a07f147f369053485da/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e906fd18d33237ff21db5ccff2b10cf3/href">https://medium.com/media/e906fd18d33237ff21db5ccff2b10cf3/href</a></iframe><p>Even worse, let’s imagine that we want to have a white background, but no divider (or just have explicit props). We will have to rewrite our BadItemComponent, for example as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf7706171e02753cf51161c612c54eca/href">https://medium.com/media/cf7706171e02753cf51161c612c54eca/href</a></iframe><p>Ugly! We can now call our Component…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b34861aeae9a0fad59be3355f274960/href">https://medium.com/media/8b34861aeae9a0fad59be3355f274960/href</a></iframe><p>Such a refactor can <strong>easily create bugs</strong> (especially for more complex components) and as you increase the number of cases, you decrease the readability and maintainability of your component.</p><p>One of the problems here came from the fact that we encapsulated “business choices” (“make the first element to be grey”) and render logic. The other problem is that we cannot remediate this problem without updating the component. <strong>We broke both the separation of concerns and the open-closed principles.</strong></p><h3><strong>The best of both worlds: The adapter</strong></h3><p>If we want to decouple our code, we can split presentation and convention. The goal here is to encapsulate the convention of your design systems in one component and the render logic in another component. It might be useful if you use your item component in many different lists and you want to keep your style consistent across all the lists of your website. We want to take the best of both worlds: consistent style but reusable components 🙌</p><p>An adapter would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98e3ed749e7f9cb11ab574db061502e3/href">https://medium.com/media/98e3ed749e7f9cb11ab574db061502e3/href</a></iframe><p>In this adapter, we set up that we want the first row of our list to be grey, and that there is no divider for the first element.</p><p>If tomorrow, we want our list to be stripped (1 element out of 2 is grey), we have only one line to update:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfa04372f26326a9f3c94af77fe142f9/href">https://medium.com/media/cfa04372f26326a9f3c94af77fe142f9/href</a></iframe><h3>Where does this leave us?</h3><p>There are thousands of things to check when you create a new component. Giving a proper API is complex (naming variables, giving flexibility, etc.).</p><p>But following simple rules, such as the Good Props/Bad Props rule, can really help 👑</p><p>Clap if you apply this rule :)</p><h3>To read elsewhere on the internet :</h3><p>A good introduction by Kent C. Dodds on Inversion of control, and how to write better (=reusable) functions and components</p><p><a href="https://kentcdodds.com/blog/inversion-of-control">Inversion of Control</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=861ee99ff90e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/react-good-props-bad-props-861ee99ff90e">React: Good Props/Bad Props</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Token authentication with React and Apollo Client— a detailed example]]></title>
            <link>https://medium.com/ovrsea/token-authentication-with-react-and-apollo-client-a-detailed-example-a3cc23760e9?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3cc23760e9</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 09:22:07 GMT</pubDate>
            <atom:updated>2020-04-06T08:15:21.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>Token authentication with React and Apollo Client— a custom hook example</h3><p>Authentication is often a pain for beginners (and experimented!) developers.</p><p>The goal of this article is to show a basic authentication system on the client side (a React App) with Apollo Client.</p><blockquote>Disclaimer : this article does not cover authentication on the backend!</blockquote><p>In this article we will cover</p><ul><li>managing your authentication token with react-cookies</li><li>passing your auth token in your headers</li><li>login &amp; logout</li><li>encapsulating the logic in reusable hooks</li></ul><p>As backend, we will use Strapi, which provides a ready to use auth system to test our frontend. You can use any backend that works with a token.</p><p>The full repo with Strapi and React is here : <a href="https://github.com/ovrsea/react-apollo-strapi-auth-example">https://github.com/ovrsea/react-apollo-strapi-auth-example</a></p><p>If you want to test it, go in /backend, do yarn install &amp;&amp; yarn start , and in /frontend, do yarn install &amp;&amp; yarn start</p><h3>Global architecture</h3><p>Below is shown the architecture that we want to implement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*EZ6DLFeSdCiu9Sf_NvViXg.png" /></figure><p>There are two “authentication data”: the auth token itself and the user data. The auth token authenticates the queries, and is thus mandatory to consider the user authenticated. The user data is a good way to “check” the authentication token : if it fails, the user has to re-login for example.</p><p>We want to give access to our App if and only if we have a token and the user query works with this token.</p><h3><strong>Managing your auth token</strong></h3><p>The first step is to manage our auth token. In this example, our auth token is stored in the cookies of the browser. It allows to persist the session even if the user leaves and comes back.</p><p>First, we have to wrap our App with a CookiesProvider</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b607c2bf15da662c54e811bc2bd17c94/href">https://medium.com/media/b607c2bf15da662c54e811bc2bd17c94/href</a></iframe><p>Then, we create a hook that allows to:</p><ul><li>get the token</li><li>save the token</li><li>remove the token</li></ul><p>Encapsulating in a custom hook will allow us to access our token easily across our App. Here is our code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6f2255c288344d0e76932f21bab9e7b/href">https://medium.com/media/c6f2255c288344d0e76932f21bab9e7b/href</a></iframe><h3><strong>Passing your auth token to your queries</strong></h3><p>Once we have a token (which we don’t have for now! 😁), we have to put the token in the headers of our requests. A classic authentication system is to put the token in the “authorization” header, under the form &quot;Bearer &lt;myToken&gt;&quot;</p><p>In our case, we have to use an Apollo Link in order to do that. A “link” is a piece of software that “modifies” the request and passes it along. For example, it can update headers, log errors, etc.</p><p>Below is the full code to configure our Apollo Client:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a5c8e7dfae8b0b8ffab2864b0bc975f/href">https://medium.com/media/5a5c8e7dfae8b0b8ffab2864b0bc975f/href</a></iframe><p>What do we have here ?</p><p>First, we have the normal configuration of an Apollo Client : http-link + cache.</p><p>Then, we created an authMiddleware that “injects” the token in our authorization header. That’s it!</p><h3><strong>Getting an auth token</strong></h3><p>At this point, if we have an auth token, we can query our backend. The thing is, we don’t have one!</p><p>In order to fetch an auth token, we have to send our login and password to the server, that will respond with a token that we have to save for further use. This is done by using the “login” mutation in our case :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86bccc0d6d28f32e2c0b3c866f638c28/href">https://medium.com/media/86bccc0d6d28f32e2c0b3c866f638c28/href</a></iframe><p>What’s interesting here is that we composed hooks. Remember our useAuthToken hook? We have now created a hook that combines useMutation and useAuthToken. This hook calls the login mutation, and if it succeeds, saves the results in our token store (the cookies!)</p><p>We can now call this hook from a basic form (using react-hook-form here) :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca62444c3b58adb8c5d298c218a170c3/href">https://medium.com/media/ca62444c3b58adb8c5d298c218a170c3/href</a></iframe><h3>Fetching the user and protecting our App</h3><p>As stated before, we also need to fetch our user once we have the token stored in our cookies. Below is a code that works for a Strapi backend :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2c5e54c9da2f7ecdb0473422c2ed354/href">https://medium.com/media/d2c5e54c9da2f7ecdb0473422c2ed354/href</a></iframe><p>Everything is in now in place, all we have to do is to decide what to serve : authentication form or protected page? In this example, we created an AuthGate, in charge of deciding :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/297ef9c64dcaeb508ee83ca5c488cc60/href">https://medium.com/media/297ef9c64dcaeb508ee83ca5c488cc60/href</a></iframe><p>We are now all set!</p><h4>Going further : logout</h4><p>Logging out is now super easy, we will create a custom hook again. Logging out will:</p><ul><li>clear apollo client cache</li><li>remove the authToken from the cookies</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/beb061657fbf40af501a0455ef6a83e2/href">https://medium.com/media/beb061657fbf40af501a0455ef6a83e2/href</a></iframe><p>We can use it in our PrivatePage for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72a36024abd288db9c35699ad4e22f8f/href">https://medium.com/media/72a36024abd288db9c35699ad4e22f8f/href</a></iframe><h4>Going further : remove the token before login</h4><p>Sometimes, having a token in the headers for the login mutation can trigger bugs (this is the case for Strapi, if the token is invalid for example). To avoid this, we can remove the token before triggering the mutation. We slightly adapt our login hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aae42a0ac92763ee94c2d1750c7fc3c1/href">https://medium.com/media/aae42a0ac92763ee94c2d1750c7fc3c1/href</a></iframe><p>You can also go further by:</p><ul><li>not re-instantiating an Apollo Client every time App renders(use useCallback or useMemo)</li><li>logging out on the server too</li><li>etc.</li></ul><p>Overall, authentication is a never ending topic. This article is a good starting point for a React + Apollo web app, but let us know in the comments how you improved this basic schema and your use case!</p><p>Happy coding!</p><h4>Interesting links on the internet :</h4><p><a href="https://kentcdodds.com/blog/authentication-in-react-applications">https://kentcdodds.com/blog/authentication-in-react-applications</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3cc23760e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/token-authentication-with-react-and-apollo-client-a-detailed-example-a3cc23760e9">Token authentication with React and Apollo Client— a detailed example</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Checking the type of an object in Typescript: the type guards]]></title>
            <link>https://medium.com/ovrsea/checking-the-type-of-an-object-in-typescript-the-type-guards-24d98d9119b0?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/24d98d9119b0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 10:17:32 GMT</pubDate>
            <atom:updated>2019-01-16T10:02:56.828Z</atom:updated>
            <content:encoded><![CDATA[<p>Coming from a JS background, checking the type of an object in Typescript is kind of obscure at first. We are used to if(obj.property) {//obj.property exists here !} and this is not possible in Typescript…</p><p>In some cases, you can use type guards. You guessed, this is what this article is about :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYAxXTUkxhiKkg2vYvxD0w.jpeg" /><figcaption>Typescript — vintage version (credits to <a href="https://medium.com/u/7ef7644c61e0">rawpixel.com</a>, via Unsplash)</figcaption></figure><h4>TL;DR/Reminder</h4><p>Type your function with is :</p><pre>function typeGuard(toBeDetermined: any): toBeDetermined is Animal {} </pre><p>or the fat arrow version:</p><pre>const tg = (tbd: any): tbd is Animal =&gt; {//return true if Animal}</pre><h3>Type checking</h3><p>Our problem is classic in Typescript: an object type is undifferentiated, and we would like to differentiate the different cases. In the example below, we have two interfaces, Animal and Person:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4504738095d55ceb04567e043eac8d2/href">https://medium.com/media/f4504738095d55ceb04567e043eac8d2/href</a></iframe><p>If we want to print the name, it’s easy.</p><p>But if we want to print “cat”, “”dog” or “human”, it becomes more complicated… Below, both functions don’t work:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e0537b6c2beaa5b21bc9da738791e63/href">https://medium.com/media/0e0537b6c2beaa5b21bc9da738791e63/href</a></iframe><p>The first one because type is not defined, the second one because instanceof works with classes. And in our case, both Person and Animal are interfaces, and there is no way instanceof will work at runtime.</p><h3><strong>Solution: A type guard</strong></h3><p>Typescript allows us to create our own function, that it will understand, and will narrow the type in the following code (in terms of scope, of course)</p><blockquote>A type guard is some expression that performs a runtime check that guarantees the type in some scope.</blockquote><blockquote>(source: <a href="http://www.typescriptlang.org/docs/handbook/advanced-types.html">http://www.typescriptlang.org/docs/handbook/advanced-types.html</a>)</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e7a374001aafce91c44653d0faac0fe/href">https://medium.com/media/6e7a374001aafce91c44653d0faac0fe/href</a></iframe><p>The key here is the type of this function: toBeDetermined is Animal . Typescript understands that if we return true, the argument is an Animal. We can now use this variable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c328562e873fd756b18fdb8a6e4a4194/href">https://medium.com/media/c328562e873fd756b18fdb8a6e4a4194/href</a></iframe><p>It works ! Magic, right ?</p><h3><strong>Warning: a type guard can introduce errors</strong></h3><p>A type guard has to be correct, otherwise it can introduce errors. Consider the following gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf2dc2350125a956917bd5830dcc68bb/href">https://medium.com/media/cf2dc2350125a956917bd5830dcc68bb/href</a></iframe><p>The type guard is definitively wrong, and yet, Typescript is OK. But at runtime, undefined appear. And you see the too classic cannot read property &#39;alpha&#39; of undefined coming…</p><h3>Going further</h3><p>If you want to learn more about typeguards, the official documentation can be a good starting point, although, as of today, it uses the good old Typescript 2.0’s typecast &lt;&gt;</p><p><a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html">Documentation - Creating Types from Types</a></p><p>If you want to write secure type guards, for example validating objects fetched from an API, you can check:</p><ul><li><a href="https://github.com/gcanti/io-ts">gcanti/io-ts</a></li><li><a href="https://spin.atomicobject.com/2018/03/26/typescript-data-validation/">Statically Typed Data Validation with JSON Schema and TypeScript</a></li></ul><p>Now you know how to narrow a type of an object :). Hope it helped !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24d98d9119b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/checking-the-type-of-an-object-in-typescript-the-type-guards-24d98d9119b0">Checking the type of an object in Typescript: the type guards</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A domain name for your (React) App]]></title>
            <link>https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c05821fd3518</guid>
            <category><![CDATA[route-53]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[domain-names]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Tue, 14 Aug 2018 13:06:42 GMT</pubDate>
            <atom:updated>2018-08-15T09:44:48.353Z</atom:updated>
            <content:encoded><![CDATA[<p>In the first two episodes, we saw how to deploy a React App on S3 very easily : <a href="https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55">https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55</a>.</p><p>Then, we saw how to optimize delivery thanks to CloudFront (part 1 : <a href="https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55">https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55</a>, part 2 to come: caching strategy, etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*5Aeht-H9PKGivcob" /></figure><p>At this point, you can access your app with an ugly URL : <a href="https://d2wrzsgbgv95na.cloudfront.net/">https://d2wrzsgbgv95na.cloudfront.net/</a>. Not really what you want to send to your friends and users…</p><p>In this post, we will see how to configure your domain name thanks to Route53.</p><h3>1. Buy your domain name</h3><p>The first step is to buy your domain name. Log in to your AWS account and go to the Route53 service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*bGtOntbPiNdeF4ImOIoWgg.png" /></figure><p>You should see something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_IvsyBXsnD6uv6ZEAZnlmQ.png" /></figure><p>Click on ‘Domains’, on the left. Then ‘Register Domain’. Buying a .com domain costs around $12 a year. The problem is generally to find one…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*MmKCER_W0vJaasYxTCljAw.png" /></figure><p>Then, click on ‘Add to cart’. Then ‘Continue’. Fill in your information as requested and click on ‘Continue’. You can then complete your purchase.</p><p>At this point, you are the owner of a domain name. Cool, isn’t it ? Now, you have to wait for the registration to be effective… It can take up to a few days, but it’s generally much shorter.</p><h3>2. Configure CloudFront</h3><p>The second step is to configure the distribution we previously created. Go back to CloudFront and click on the distribution.</p><p>In the General Tab, we have to edit a few things:</p><h4>Alternate Domain Names (CNAMES)</h4><p>The domain name(s) you want. For example app.ovrsea.org and ovrsea.org</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*O5_Crj7-bLxys2aB-ucXtQ.png" /></figure><h4>Custom SSL</h4><p>If you want to support HTTPS (and you want to !), you have to create a certificate. Pick ‘Custom SSL Certificate’ and click on ‘Request or Import a Certificate with ACM’.</p><p>In your domain name, for simplicity reasons, I encourage you the add your root domain and a domain with a wild card as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*HtjLttSPXkmlBhkn8LVxPA.png" /></figure><p>Validate. Pick DNS Validation (automatic if you bought the domain from AWS). Validate, validate, validate… And wait !</p><p>You should see something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*lg8wgicWzT5UxF9-c7MePA.png" /></figure><p>The goal here is for Amazon to be sure that you really own the domain. And the method is to let you add a specific key to your DNS Records, that Amazon will regularly check. If you could add this to your domain, then it means you own it, and Amazon delivers the certificate.</p><p>Well, what’s cool is that you bought your domain from Amazon ! So open the domain, and click on ‘Create record in Route 53’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*njS9ddPuBF5IWnjGDTXFvQ.png" /></figure><p>We now have to wait (again…) the validation. It should not be long.</p><p>Then, you can close this tab and come back on the CloudFront configuration, General Tab. Normally, Custom SSL Certificate should be selected. In the input below, pick you certificate you juste created. Click on ‘Yes, Edit’ to save the new configuration.</p><h3>3. Configure Route 53</h3><p>Almost done ! Last step: configure our domain and subdomains to point to our CloudFront distribution.</p><p>If you come back to Route53, you should see 1 hosted zone now. Click on Hosted Zones. Click on the one you just created :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQoUNtptybjnPOwdaTZmOw.png" /></figure><p>You are now in the Zone Configuration Screen. It should look like this (plus the validation records…):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmZH0VCP7J09VRhVxFRVfg.png" /></figure><p>We will now create the good records : click on ‘Create Record Set’.</p><p>Enter the subdomain you want (leave empty for the root domain). For example, for app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*fNk4mt7E_rYh7fPuvS5wvQ.png" /></figure><p>Tick Yes for Alias, and pick you CloudFront distribution below. Save. Repeat for your different names. And guess what ? We have to wait again…</p><p>DNS propagation can take up to 24 hours. However, it’s generally shorter for closer zones (1 minute while I was writing this phrase, wow !).</p><h3>4. Enjoy !</h3><p>Our app is now accessible at <a href="http://app.ovrsea.org/">app.ovrsea.org</a> and <a href="http://ovrsea.org/">ovrsea.org</a>. Cool :) !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*OY1s4kYvPAppiH_I.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c05821fd3518" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518">A domain name for your (React) App</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deliver your React App in milliseconds with CloudFront]]></title>
            <link>https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd3a2d038445</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[cloudfront]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 07:51:40 GMT</pubDate>
            <atom:updated>2018-10-26T15:10:42.335Z</atom:updated>
            <content:encoded><![CDATA[<p>You uploaded you React App on a S3 Bucket thanks to <a href="https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55">https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55</a>.</p><p>Then what ? Then…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*zP2694niC-yY4Por.jpg" /><figcaption>Cloudfront</figcaption></figure><p>Using S3 is not the end of the story. Adding CloudFront in front of S3 allows you to :</p><ul><li>deliver your app with a lower ping</li><li>gzip your app</li><li>manage different subdomains on the same bucket and hence the same build</li><li>enable HTTPS</li></ul><h3>The advantages of using CloudFront</h3><p>CloudFront is a Content Delivery Network: <a href="https://en.wikipedia.org/wiki/Content_delivery_network">https://en.wikipedia.org/wiki/Content_delivery_network</a>. It delivers static assets faster across the globe. And guess what ? Our React App is a static asset ! Let’s see the different advantages in details:</p><p><strong>Gzip + Low Ping: </strong>Below<strong> </strong>is a comparison between delivering our React app from S3 or from CloudFront:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*m8f8L_injWVlG-nIH1GXZw.png" /><figcaption>Directly from S3 — General</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*pYEdozEsicO0rFMlwix4Vg.png" /><figcaption>Directly form S3 — main.js details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*uQXz-7pAXuK5AfrUZ0TskA.png" /><figcaption>With CloudFront — General</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*kj_n2UqqvPag5dIkC4Z4Pw.png" /><figcaption>With CloudFront — main.js details</figcaption></figure><p>As you can see:</p><ul><li>CloudFront gzips your content: our main bundle went down from 115 kB to 38 kB. It is huge (x3 !), especially when your app grows and on mobile networks</li><li>The ping is lower: 18 ms against 110 ms with S3</li><li>Overall, downloading the main assets took 125 ms with Cloudfront, more than 250 ms with S3. Not bad !</li></ul><p><strong>Multiple subdomains/routes:</strong> We will come back on managing subdomains on the same bucket in a next article about prerendering your pages.</p><p><strong>HTTPS:</strong> S3 does not support HTTPS… Using CloudFront is mandatory to enable HTTPS, and using HTTPS is a must do: <a href="https://developers.google.com/web/fundamentals/security/encrypt-in-transit/why-https">https://developers.google.com/web/fundamentals/security/encrypt-in-transit/why-https</a></p><h3>Configuration</h3><p>Configuring CloudFront is much easier than deploying on S3…</p><p>First, we go to the CloudFront panel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fH8ACkUTLUkBeEgaMakYEg.png" /></figure><p>Click on “Create Distribution”, then “Get Started” in the Web section</p><p>Here we go…</p><h4>Origin Settings</h4><p>The only field you have yo fill is Origin Domain Name. We take our website origin, that you can find in your S3 bucket, tab “Properties”, panel “Static Website Hosting”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*OExTo0PbdTvc-e5e5AHs4w.png" /><figcaption>The website URL is the “endpoint”</figcaption></figure><h4>Default Cache Behavior</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*lrHWpJS14195sPDOK4jK1g.png" /></figure><p>The only thing you have to turn on is “Compress Object Automatically”. I also encourage you to redirect HTTP traffic to HTTPS, but it’s not mandatory.</p><h4>Distribution Settings</h4><p>Leave it as it is. In the next article, we will cover how to add a domain name to your app, and we will come back on this section.</p><p>Click on Create the Distribution.</p><p>You should see it being deployed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21yog9wdgD9KPVpO_cQB4Q.png" /><figcaption>Deployment in progress…</figcaption></figure><p>When it’s done, you can access your website at the “Domain Name”. In our case: https://d2wrzsgbgv95na.cloudfront.net</p><p>It’s all set ! Your app is now optimally delivered.</p><p>In the next articles, we will cover:</p><ul><li>Domain Name Configuration with Route 53 (better have app-demo.ovrsea.com than d2wrzsgbgv95na.cloudfront.net, right ?) (<a href="https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518">https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518</a>)</li><li>Route Prerendering for a faster user experience (WIP)</li></ul><p>Feel free to comment or reach me, should you have any question or remark :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd3a2d038445" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445">Deliver your React App in milliseconds with CloudFront</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[mapStateToProps, and why you may not need mapDispatchToProps when you start Redux]]></title>
            <link>https://medium.com/ovrsea/mapstatetoprops-and-why-you-may-not-need-mapdispatchtoprops-as-a-beginner-dd012a3da5e6?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd012a3da5e6</guid>
            <category><![CDATA[mapstatetoprops]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Wed, 09 May 2018 13:34:32 GMT</pubDate>
            <atom:updated>2018-12-26T13:37:00.962Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started React+Redux, one of the first things I did not understand were the obscure mapDispatchToProps and mapStateToProps functions. Although the documentation is clear for experimented Redux users, I will try to explain a bit differently and write what I wish someone told me when I began.</p><p>TL;DR: you can skip the very beginning</p><h3>The very beginning: Higher-Order Components</h3><p>Redux uses the notion of higher-order component (nickname HOC). It is often described as a React pattern, a wonderful way to refactor code, etc. That’s true. However, the documentation (<a href="https://reactjs.org/docs/higher-order-components.html">https://reactjs.org/docs/higher-order-components.html</a>) is definitively obscure for a beginner, especially if you have an Object Oriented background. So, I will summarize here what you need to know to start:</p><p>A Higher Order Component is just a way to enhance normal components. How does it work ?<strong> It adds props to your components !</strong></p><p>Let’s see a basic example: you have two components, DisplayHello and DisplayQuestion. They both need to access the same info, the nickname of our user.<strong> The basic way to do that is to propagate props from the root of your app (which maintains a state) as presented below</strong>:</p><p>App.js:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>DisplayHello <strong>from </strong>&quot;./DisplayHello&quot;;<br><strong>import </strong>DisplayQuestion <strong>from </strong>&quot;./DisplayQuestion&quot;;<br><br><strong>class </strong>App <strong>extends </strong>Component {<br>    state = {<br>        username: &#39;ovrsea&#39;,<br>    };<br>    <br>    render() {<br>        <strong>return </strong>(<br>            &lt;div&gt;<br>                &lt;DisplayHello username={<strong>this</strong>.state.username}/&gt;<br>                &lt;DisplayQuestion username={<strong>this</strong>.state.username}/&gt;<br>            &lt;/div&gt;<br>        );<br>    }<br>}<br><br><strong>export default </strong>App;</pre><p>DisplayHello.js:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><br><strong>class </strong>DisplayHello <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;p&gt;<br>                Hello {<strong>this</strong>.props.username} !<br>            &lt;/p&gt;<br>        );<br>    }<br>}<br><br><br><strong>export default </strong>DisplayHello;</pre><p>DisplayQuestion.js:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><br><strong>class </strong>DisplayQuestion <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;div&gt;<br>                What do you want to order today, {<strong>this</strong>.props.username} ?<br>            &lt;/div&gt;<br>        );<br>    }<br>}<br><br><br><strong>export default </strong>DisplayQuestion;</pre><p>However, it could become heavy to handle if you have a lot of information and/or components. It is not the role of the root to handle your app data ! This is where HOC are useful. We create a component which “pushes” the info to the components which need them ! How does it work ?<strong> It is just a function that takes a component as input and returns the same component with new props.</strong> The code of this magic trick is below :</p><pre><strong>import </strong>React, { Component } <strong>from </strong>&#39;react&#39;<br><strong>export default function </strong>ourFirstStore(WrappedComponent) {<br>    <strong>return class extends </strong>Component {<br>        state = {<br>            username: &#39;ovrsea&#39;,<br>        };<br><br>        render() {<br>            <strong>return </strong>&lt;WrappedComponent username={<strong>this</strong>.state.username} {...<strong>this</strong>.props} /&gt;;<br>        }<br>    };<br>}</pre><p>DisplayHello updated:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>ourFirstStore <strong>from </strong>&quot;./ourFirstStore&quot;;<br><br><strong>class </strong>DisplayHello <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;p&gt;<br>                Hello {<strong>this</strong>.props.username} !<br>            &lt;/p&gt;<br>        );<br>    }<br>}<br><br><br><strong>export default </strong>ourFirstStore(DisplayHello);</pre><p>DisplayQuestion updated:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>ourFirstStore <strong>from </strong>&quot;./ourFirstStore&quot;;<br><br><strong>class </strong>DisplayQuestion <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;div&gt;<br>                What do you want to order today, {<strong>this</strong>.props.username} ?<br>            &lt;/div&gt;<br>        );<br>    }<br>}<br><br><br><strong>export default </strong>ourFirstStore(DisplayQuestion);</pre><p>And App.js:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>DisplayHello <strong>from </strong>&quot;./DisplayHello&quot;;<br><strong>import </strong>DisplayQuestion <strong>from </strong>&quot;./DisplayQuestion&quot;;<br><br><strong>class </strong>App <strong>extends </strong>Component {<br><br>    render() {<br>        <strong>return </strong>(<br>            &lt;div&gt;<br>                &lt;DisplayHello/&gt;<br>                &lt;DisplayQuestion/&gt;<br>            &lt;/div&gt;<br>        );<br>    }<br>}<br><br><strong>export default </strong>App;</pre><p><strong>You can notice that all the data is now in the wrapper and not in App.js anymore</strong>. We just created a very basic data store accessible anywhere in your app !</p><p>Redux uses (almost) the same idea to give you the possibility to access the data, but also to modify your store. And as we have seen, this data and methods are accessible through props. This is why we have to… mapStateToProps and mapDispatchToProps !</p><h3>mapStateToProps, the easy one: access your data</h3><p>If you understood the previous example, you see how easy it is to access data from a store. The problem is: your store might be huge, and your component does not need to be aware of all the changes in it. <strong>You want to choose which variables are accessed by which component. </strong>This is where mapStateToProps comes into action !</p><p>Basically, this function tells your component what props will be added. You need state.username ? Then add it! The email ? Same. The “map” itself is just an object returned by your function.</p><p>If our state looks like this:</p><pre>{<br>    username: ‘initial name’<br>}</pre><p>then, our component will be:</p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>{connect} <strong>from </strong>&quot;react-redux&quot;;<br><br><strong>class </strong>DisplayQuestion <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;div&gt;<br>                What do you want to order today, {<strong>this</strong>.props.nameAsProps} ?<br>            &lt;/div&gt;<br>        );<br>    }<br>}<br><br><strong>function </strong>mapStateToProps(state){<br>    <strong>return </strong>{<br>        nameAsProps: state.username,<br>    }<br>}<br><br><strong>export default </strong>connect(mapStateToProps)(DisplayQuestion);</pre><p>Easy, isn’t it ?</p><h3>mapDispatchToProps, the tricky one. That you don’t need at first.</h3><p>The only way to update data in your store is to <strong>dispatch</strong> actions. Well, something only a few know: <strong>dispatch is accessible as a props if you don’t provide a mapDispatchToProps function.</strong></p><p>So, my 2 cents here if you are a true React + Redux beginner: don’t use mapDispatchToProps ! You certainly don’t need to understand the concept of middleware, nor what an action creator is, for now. Those are powerful patterns, of course. But I wish someone told me: “don’t worry, you will understand later”.</p><p>So here is a simple app: you have an initial name, let’s say ‘initial name’, and when you click on a button, it changes the name, to, let’s say ‘new name’. Then, our component can look like this:</p><p><strong>ChangeNameButton.js:</strong></p><pre><strong>import </strong>React, {Component} <strong>from </strong>&#39;react&#39;;<br><strong>import </strong>{connect} <strong>from </strong>&quot;react-redux&quot;;<br><br><strong>const </strong>action = {<br>    type: &#39;MODIFY_USERNAME&#39;,<br>    payload: &#39;new name&#39;,<br>};<br><br><strong>class </strong>ChangeNameButton <strong>extends </strong>Component {<br>    render() {<br>        <strong>return </strong>(<br>            &lt;input<br>                type=&quot;button&quot;<br>                value=&quot;Change my name !&quot;<br>                onClick={() =&gt; <strong>this</strong>.props.dispatch(action)}<br>                /&gt;<br>        );<br>    }<br>}<br><br><strong>export default </strong>connect()(ChangeNameButton);</pre><p>and our store (+ reducer here, but it’s better if you have separate files) :</p><p><strong>store.js:</strong></p><pre><strong>import </strong>{ createStore } <strong>from </strong>&#39;redux&#39;<br><br><strong>function </strong>modify_username(state = {username: &#39;initial name&#39;}, action) {<br>    <strong>switch </strong>(action.type) {<br>        <strong>case </strong>&#39;MODIFY_USERNAME&#39;:<br>            <strong>return </strong>{username: action.payload}<br>        <strong>default</strong>:<br>            <strong>return </strong>state<br>    }<br>}<br><br><strong>export default </strong>createStore(modify_username);</pre><p>Let’s try ! On the right, you can see the store state and the dispatched actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnF3gciFR9Pi2B0aE0aIcA.png" /><figcaption>Before clicking…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rds7mdtjgitwgPEd4ymgKQ.png" /><figcaption>…and after clicking: the action has been dispatched, and the store updated</figcaption></figure><h3>Going further: using mapDispatchToProps</h3><p>The goal of this article was to show a very basic architecture to understand the concept of connected components, store, dispatch, etc. If you use dispatch directly as a props, you will soon see that you cannot really reuse your actions. It will be also more difficult to pass parameters. So, once you are familiar with those concepts, feel free to use mapDispatchToProps :) !</p><p>Happy coding !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd012a3da5e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/mapstatetoprops-and-why-you-may-not-need-mapdispatchtoprops-as-a-beginner-dd012a3da5e6">mapStateToProps, and why you may not need mapDispatchToProps when you start Redux</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Je ne pensais pas que ça pouvait être aussi simple”]]></title>
            <link>https://medium.com/@antoine_52391/je-ne-pensais-pas-que-%C3%A7a-pouvait-%C3%AAtre-aussi-simple-2e39c3782631?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e39c3782631</guid>
            <category><![CDATA[export]]></category>
            <category><![CDATA[cosmetics]]></category>
            <category><![CDATA[usa]]></category>
            <category><![CDATA[freight-forwarding]]></category>
            <category><![CDATA[international-trade]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Mon, 07 May 2018 12:22:34 GMT</pubDate>
            <atom:updated>2018-05-24T14:15:29.162Z</atom:updated>
            <content:encoded><![CDATA[<p>L’expérience de la logistique internationale par La Bouche Rouge</p><p>La Bouche Rouge Paris est une nouvelle Maison de maquillage française qui réconcilie éco-responsabilité et luxe. Lancée en novembre 2017, les premiers rouges à lèvres de la Maison sont fabriqués en France dans la tradition de l’excellence artisanale française, rechargeables et sans plastique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Lr_0ftr84rnQ-bboQAG-OQ.jpeg" /><figcaption>Credit : babillages.net</figcaption></figure><p>En vente au Bon Marché à Paris, en ligne sur laboucherougeparis.com, chez The Webster à Soho, et bientôt dans les huit boutiques Barneys New York aux Etats Unis.</p><p>En Mars 2018, La Bouche Rouge est à un tournant de son histoire. Barneys, le grand magasin référence dans la distribution de produits de luxe aux Etats-Unis, lui propose d’être son distributeur et lui ouvre la porte du marché américain. C’est une “opportunité exceptionnelle de développement international” qui permet à leur marque, quelques mois seulement après leur lancement, de se faire une renommée Outre Atlantique.</p><blockquote><em>“Le transport, les douanes… tout cela me semblait être une montagne à gravir”</em></blockquote><p>Problème : ils ont alors une semaine et demi pour exporter cinq palettes de rouge à lèvre dans les entrepôts de Barneys à New York. Violette et Nicolas, fondateurs de la Bouche Rouge, ont une vision stratégique et marketing mais ils ignorent tout du transport international et de la logistique.</p><p>C’est alors que Violette prend contact avec OVRSEA et s’inscrit sur la plateforme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*dVGFLFjbbXi7pSkh2Ns5xQ.png" /><figcaption>La gestion des marchandises</figcaption></figure><p>Violette apprend alors qu’elle doit réaliser différentes formalités avant d’être en mesure d’exporter :</p><ul><li>être enregistrée auprès des douanes américaines</li><li>être enregistrée auprès de la FDA</li><li>signer un mandat de représentation en douanes</li></ul><p>Elle doit également :</p><ul><li>réaliser une demande de cotation pour obtenir un devis de transport</li><li>fournir une packing list et une facture commerciale pour la bonne réalisation de son transport</li></ul><p>Alors que ces formalités sont très souvent chronophages et basées sur du papier, Violette en réalise la majorité très simplement sur la plateforme OVRSEA.</p><p>En l’espace de quelques jours, La Bouche Rouge :</p><ul><li>est enregistrée auprès des douanes américaines</li><li>est enregistrée auprès de la FDA (Food and Drug Administration)</li><li>dispose d’une réservation sur un vol de marchandises pour New York.</li></ul><p>Le transport se déroule sans embûches à la plus grande satisfaction de La Bouche Rouge et de Barneys. La conquête du marché américain peut commencer.</p><p>Avec OVRSEA, Violette a trouvé “une solution logistique rapide et efficace qui a su anticiper les problèmes”, et faire preuve d’une “flexibilité et d’une réactivité exceptionnelles.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*mTnjGN8IqNj1Op9QnFxsKA.png" /><figcaption>L’interface de tracking</figcaption></figure><blockquote><em>“OVRSEA en trois mots ? Pédagogie, Transparence, Efficacité”</em></blockquote><p>L’apport de l’interface web a été un “avantage de taille” et une des raisons pour lesquelles elle recommande cette “solution clé en main”. Elle qualifie la plateforme de “simple” et “rassurante”. Elle apprécie également la “visibilité disponible en ligne” une fois le transport programmé.</p><p><a href="http://www.ovrsea.com/home/"><strong>OVRSEA :</strong></a> Notre mission est de simplifier et optimiser le transport international pour les entreprises. Nous sommes heureux d’accompagner La Bouche Rouge. Nous leur souhaitons un franc succès sur le marché américain.</p><p><em>Originally published at </em><a href="https://blog.ovrsea.com/2018/05/07/je-ne-pensais-pas-que-ca-pouvait-etre-aussi-simple/"><em>blog.ovrsea.com</em></a><em> on May 7, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e39c3782631" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a React App on Amazon S3 (+ IAM) within minutes (and redeploy automatically)]]></title>
            <link>https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55?source=rss-cd64a2df4fcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/da6cb0096d55</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[create-react-app]]></category>
            <dc:creator><![CDATA[Antoine Sauvage]]></dc:creator>
            <pubDate>Tue, 21 Nov 2017 11:04:28 GMT</pubDate>
            <atom:updated>2018-11-16T14:57:43.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XRkyGeE47qCyDCdowAACwA.png" /><figcaption>The perfect match !</figcaption></figure><p>[EDIT: this is the first episode of 3: at the end, you will have a React app, accessible from your domain name, optimally delivered via CloudFront.]</p><p>Part 2: <a href="https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445">Deliver your app in milliseconds via Cloudfront</a></p><p>Part 3: <a href="https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518">A domain name for your (React) App</a></p><p>React is an awesome Framework to develop webapps. At <a href="https://www.ovrsea.com,/">Ovrsea</a>, we are definitively fans ! You can build a new one within minutes. The question is: how to make it available online easily and for free?</p><p>The first good news is that a React App is static. It means that once you built all your files, you don’t need a server to execute any instruction. Everything is handled by the browser. The second good news is that it costs almost nothing to host a static website on S3, the static content hosting service by Amazon. The third good news is that you can easily deploy any update automatically thanks to the S3 CLI. The perfect match !</p><p>If you want to discover how to hassle-free deploy your React app and update it in one command line, this tutorial is made for you. We will cover:</p><ul><li>creation of a basic React App</li><li>configuration of a free AWS account</li><li>configuration of your environment</li><li>(re)deployment of your app</li></ul><h3>Create-React-App</h3><p>This part is more than easy thanks to the wonderful ‘create-react-app’ scripts (<a href="https://github.com/facebookincubator/create-react-app">https://github.com/facebookincubator/create-react-app</a>).</p><p>First, install npm (as part of Node.js <a href="https://www.npmjs.com/get-npm?utm_source=house&amp;utm_medium=homepage&amp;utm_campaign=free%20orgs&amp;utm_term=Install%20npm">https://www.npmjs.com/get-npm</a>). Then, type in your terminal:</p><pre>npm install -g create-react-app</pre><p>It installs all the scripts you will need. The -g stands for ‘global’, meaning that you will be able yo create React Apps everywheeeeere !</p><p>Then, where you want to create your ‘wonderful-app’, type:</p><pre>create-react-app wonderful-app</pre><p>To test your app, go into the folder:</p><pre>cd wonderful-app</pre><p>and start it with npm (it also works with yarn) !</p><pre>npm start</pre><p>You should see a basic webapp like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jT5VNaAST4TtuXZ3_bpTg.png" /></figure><p>Stop the app (Ctrl + C or Cmd+C).</p><h3>AWS configuration</h3><p>You need to create an AWS account to deploy a website on S3. S3 is included in the free tier, meaning that below 20k requests on your website (and below 5 Go served), it is free of charge for a year !</p><p>To create an account, go to <a href="https://aws.amazon.com/">https://aws.amazon.com/</a> and follow the instructions. Once ready, we can go on:</p><h4>IAM Profile (optional)</h4><p>It is not recommended to use the root account (the one you just created) everywhere. Instead, it is better to create dedicated users according to your needs.</p><p>First, log in to your acount. Go to the IAM manager:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSVTz4WCUTGOzUJ0S0tZ3A.png" /></figure><p>Then, click on the “Users” menu on the left, and “Add User”. Fill the fields Username and tick “Programmatic access”. You should see something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2xxkRaNjvfyCC7UIHENyg.png" /></figure><p>Click on “Next: Permissions”. We know have to attach to this user the rights to use s3. This is given by a policy named “AmazonS3FullAccess”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3snwiOhKjJUpns_I-Vjkug.png" /></figure><p>Then, validate the creation of the user. At step 4, an Access key ID and a secret access key are given to you. Save them somewhere for later:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z084A8b_gZJn5mAQhw3gWg.png" /></figure><h4><strong>Key creation (for those who did not create an IAM User)</strong></h4><p>If you prefer using you root account (not recommended !), you can create access keys by clicking on your name on top right corner, then “My Security Credential”, and “Access keys”. There, you can “Create new Access key”. Save the key in a very secure place !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYhRJv87bZTwMqSmuYq3FQ.png" /></figure><h4>AWS CLI</h4><p>We will now install the AWS CLI. The AWS CLI is… a tool to manage all your AWS services through a CLI. Amazing !</p><p>The Amazon documentation is pretty clear (<a href="http://docs.aws.amazon.com/cli/latest/userguide/installing.html">http://docs.aws.amazon.com/cli/latest/userguide/installing.html</a>), the platform specific procedures are described at the bottom of the page.</p><p>Once you installed the tool, open a new terminal, and type <strong>aws configure</strong></p><p>You will be asked your Access Key ID and Secret Access Key created earlier (for those who read too fast, in the previous section !).</p><p>You don’t have to chose your region and output format (just type Enter).</p><h4>S3 Bucket creation</h4><p>We are almost there ! We now have to create a bucket to host our app. Choose the S3 service :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMQzhHOuXBdypg3nyVzlig.png" /></figure><p>Create a new bucket. You can choose the region close to your users. However, we will see in another article how to use Cloudfront to deliver your content as fast as possible all over the world. So it does not really matters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKGNlogYGdCWIvFQBEtZIQ.png" /></figure><p>Then, next, next, next until you bucket is created. Select the bucket once it is done. You should see something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edF2F6jx4SBJArQGb-R3yQ.png" /></figure><p>We have to:</p><ul><li>update permissions</li><li>set up the bucket as static hosting</li></ul><p>To update permissions, go to “Permissions”, click on “Bucket Policy”, and “Policy Generator”. You should see a form as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhjcVl_fEOHuhc9Jirv2TQ.png" /></figure><p>Fill Step 1: S3 Bucket Policy</p><p>Fill Step 2: Effect: Allow, Principal: *, AWS Service: Amazon S3, Actions: “GetObject”. For the ARN, you have to take the name of your bucket, and add /* at the end (meaning everyone can access all your files).</p><p>In my case, it is: <strong>arn:aws:s3:::wonderful-app/*</strong></p><p>Click on “Add Statement”, and “Generate Policy”. It should generate a policy like this one:</p><pre>{<br>  &quot;Id&quot;: &quot;Policy1511261302545&quot;,<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;Stmt1511261285825&quot;,<br>      &quot;Action&quot;: [<br>        &quot;s3:GetObject&quot;<br>      ],<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:s3:::wonderful-app/*&quot;,<br>      &quot;Principal&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p>Copy and paste it into your bucket policy, and save:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4eR1pG5JSSoHZ0RiLJS3Rw.png" /></figure><p>Go to “Properties”, “Static Website Hosting”. Select use this bucket to host a website, fill the form and click save (and bookmark the URL given on top of the card):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPPGSAP38qxX394G1rYdWA.png" /></figure><p>AWS is now ready !</p><h3><strong>Deploy your app !</strong></h3><p>Now that everything is configured, it should work like a charm.</p><p>Add a line “deploy” to your <strong>package.json</strong> (syncing your “build” folder with you s3 bucket):</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;react-scripts start&quot;,<br>  &quot;build&quot;: &quot;react-scripts build&quot;,<br>  &quot;deploy&quot;: &quot;aws s3 sync build/ s3://wonderful-app&quot;,<br>  &quot;test&quot;: &quot;react-scripts test --env=jsdom&quot;,<br>  &quot;eject&quot;: &quot;react-scripts eject&quot;<br>}</pre><p>Run npm run build (it bundles and optimizes your app for production), and then npm run deploy. It’s all set !</p><p>You can now access your app !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UuBqN-eTbW_3mWKZhQklYA.png" /></figure><p>Anytime you want to update you app, juste run npm run build and npm run deploy !</p><p>Enjoy !</p><p>In the next articles, you can learn to:</p><ul><li>Configure Cloudfront to deliver you app efficiently <a href="https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445">https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445</a></li><li>Configure Route 53 for your domain name, because a cool domain name is… cool !(<a href="https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518">https://medium.com/ovrsea/a-domain-name-for-your-react-app-c05821fd3518</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da6cb0096d55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ovrsea/deploy-automatically-a-react-app-on-amazon-s3-iam-within-minutes-da6cb0096d55">Deploy a React App on Amazon S3 (+ IAM) within minutes (and redeploy automatically)</a> was originally published in <a href="https://medium.com/ovrsea">OVRSEA</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>