<?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 Tom Medema on Medium]]></title>
        <description><![CDATA[Stories by Tom Medema on Medium]]></description>
        <link>https://medium.com/@tommedema?source=rss-d680fc1f4bd9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nIzk3fUnQYgQxAhP.</url>
            <title>Stories by Tom Medema on Medium</title>
            <link>https://medium.com/@tommedema?source=rss-d680fc1f4bd9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:02:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tommedema/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[Natively copying url to clipboard on desktop and mobile]]></title>
            <link>https://medium.com/@tommedema/natively-copying-url-to-clipboard-on-desktop-and-mobile-3da658401321?source=rss-d680fc1f4bd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da658401321</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Tom Medema]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 18:45:34 GMT</pubDate>
            <atom:updated>2019-09-11T18:45:34.243Z</atom:updated>
            <content:encoded><![CDATA[<p>While I was working on a new app I needed a quick solution to let the user copy the current url to their clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*lfguhLscE36aPtAZUewQAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*UeKL_kushHgSg2EOptcdOA.png" /><figcaption>Desired “copy link” component in its static (left) and copied (right) states</figcaption></figure><p>We wanted the user to know what they are copying, so it made sense to show a read-only input element with a “copy link” button to the right. I quickly learned that there’s a native way to achieve this behavior and wanted to share this little snippet with you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9ccd05a900a652d9c3f33284a293359/href">https://medium.com/media/d9ccd05a900a652d9c3f33284a293359/href</a></iframe><p>Notice the <em>inputHTMLElement.setSelectionRange(0, inputHTMLElement.value.length) —</em> it took me a bit of time to figure out that this was necessary to get the copy command to behave as expected on iOS 12.</p><p>If you wanted to use React, you’d have to create a reference to the HTML input element. Here’s a complete example of a ShareButton.tsx component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7538f46d226264902a30408e71f2af2e/href">https://medium.com/media/7538f46d226264902a30408e71f2af2e/href</a></iframe><p>Let me know if this is useful and if you have any feedback!</p><p>If you’re curious what service I was building this for, it’s for a neat little chrome extension that allows you to screenshot any website, drop annotations on it, and share the result with your friends &amp; colleagues. Check out <a href="http://www.usebubbles.com/">www.usebubbles.com</a> if this sounds useful to you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da658401321" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DocumentClient-like parsing of DynamoDBStream items]]></title>
            <link>https://medium.com/@tommedema/documentclient-like-parsing-of-dynamodbstream-items-898c3a3d7725?source=rss-d680fc1f4bd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/898c3a3d7725</guid>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Tom Medema]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 19:40:26 GMT</pubDate>
            <atom:updated>2019-09-04T19:40:26.952Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re into the whole Node.js / Lambda / AWS stack like me you’ll likely be using AWS’ <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html">DocumentClient</a>. It neatly abstracts away DynamoDB’s underlying data types to native Javascript types.</p><p>But what if you’re not retrieving DynamoDB records from DocumentClient, but rather from a DynamoDB stream that is triggering your lambda? In this case you’ll have to do the conversion yourself. Fortunately AWS has a public <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/Converter.html">Converter API</a> that comes to the rescue.</p><p>Given a DynamoDB table with a stream specification:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d705591ef7591da314fe76471ec4d3c/href">https://medium.com/media/9d705591ef7591da314fe76471ec4d3c/href</a></iframe><p>And a lambda function that is triggered on each new record (here using the Serverless Framework):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2405182f3b8964bb3b9b1b209bff707e/href">https://medium.com/media/2405182f3b8964bb3b9b1b209bff707e/href</a></iframe><p>We can retrieve and convert each record within the lambda:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2df76417eebbf785501cdec7ef4966a8/href">https://medium.com/media/2df76417eebbf785501cdec7ef4966a8/href</a></iframe><p>Which then gives us machine readable records with a type equal to the type that we inserted using the DocumentClient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=898c3a3d7725" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Typescript confusion: tsconfig.json module, moduleResolution, target & lib explained]]></title>
            <link>https://medium.com/@tommedema/typescript-confusion-tsconfig-json-module-moduleresolution-target-lib-explained-65db2c44b491?source=rss-d680fc1f4bd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/65db2c44b491</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tom Medema]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 01:21:36 GMT</pubDate>
            <atom:updated>2019-07-30T01:21:36.591Z</atom:updated>
            <content:encoded><![CDATA[<p>I find myself creating new Typescript projects over and over. I simply copy-paste previous tsconfig.json files and more often than not it “just works”. Yet I can’t help but feel like something stinks in my approach. Instead of copying what works, I decided to start from scratch and force myself to fully understand each and every config parameter. Four options in particular were rather confusing so I decided to share my findings.</p><p>One key take-away for me is that these options are mostly about what Typescript compiles <em>to</em>, and not <em>from. </em>This is different from Babel where both input (parsing) and output (compilation) settings exist. So, no matter how you configure Typescript, the Typescript language syntax remains the same.</p><h3>Module</h3><p>Module defines the <em>output</em> module resolution system that is used. For example, if you would use “es2015” here, it would assume that your Javascript engine is capable of parsing es2015 import statements (e.g. this would fail in Node.js 8). If you would set this to “commonjs”, it would export the module using the exports property (and therefore would run in e.g. Node.js 8). I keep this set to “commonjs” for my purposes.</p><h3>ModuleResolution</h3><p>This configures how the compiler tries to find your modules (resolve them). There are two strategies for doing so: classic or node. I set this to node because I am used to how node resolves modules. Node is now Typescript’s default mode of module resolution, i.e. classic is mostly present for backwards compatibility.</p><h3>Target</h3><p>Target is related to the <em>output</em> of your code, i.e. the compiled code targets a specific language variant. If you specify ES5 (not to be confused with ES2015), the compiled code can be run by ES5-compliant browsers and engines like Node. If you specify ES6 (== ES2015), the compiled code cannot be run by browsers or engines that do not yet support ES6 (ES2015) features. I set this to “es2015” because I am running my compiled code on AWS Lambda, which runs Node.js 8 and <a href="https://node.green/#ES2015">supports most es2015 features</a>.</p><h3>Lib</h3><p>Also related to the <em>output</em> of your code, this tells the compiler which language features are available when the compiled code is run. In most cases this would be the same as “target”, except if you polyfilled the runtime environment. For example, you might have polyfilled the Promise class in an ES5 environment.</p><p>Note that as opposed to Babel, Typescript does not actually down-compile all language features such as Promises. It does down-compile a few language constructs (rather than APIs), such as async/await.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65db2c44b491" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hot module reloading with create-react-app v3]]></title>
            <link>https://medium.com/@tommedema/hot-module-reloading-with-create-react-app-v3-f2c7afe1dae8?source=rss-d680fc1f4bd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2c7afe1dae8</guid>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[hot-module-replacement]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tom Medema]]></dc:creator>
            <pubDate>Sun, 19 May 2019 02:06:05 GMT</pubDate>
            <atom:updated>2019-06-14T16:25:30.943Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stateful Hot Module Replacement with create-react-app v3</h3><p>When I was first told about Hot Module Replacement (HMR) the term “hot” seemed to indicate to me that components would update on-the-fly while preserving your app’s state. E.g. if you’re developing a multi-step form, and you’re currently working on step 3 out of 5, you wouldn’t have to go through steps 1 and 2 again to see how your code changes affected step 3.</p><p>Surprisingly, HMR only seems to refer to the replacement of a component, meaning that that component’s state is lost. To get HMR to work with create-react-app (CRA) v3, while preserving state, I had to go through the following steps.</p><h3>Re-configure babel</h3><p>First install the following dependencies:</p><pre>npm install --save-dev react-app-rewired react-hot-loader react-app-rewire-hot-loader <a href="http://twitter.com/hot">@hot</a>-loader/react-dom</pre><p><a href="https://github.com/timarney/react-app-rewired">React-app-rewired</a> allows you to implement small variations to CRA’s default babel configuration, while still being able to merge back in future updates to CRA. <a href="https://github.com/gaearon/react-hot-loader">React-hot-loader</a> is what takes care of preserving state when webpack’s devserver hot reloads your components. Finally, <a href="https://github.com/hot-loader/react-dom">@hot-loader/react-dom</a> is what allows state from React’s <a href="https://reactjs.org/docs/hooks-intro.html">latest hooks</a> such use useState to also be preserved.</p><p>Then make sure that you replace your package.json’s react-scripts start command with react-app-rewired start. This will make sure that your configuration “patches” will take effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*Bng78iYmcmYEFaz3WpWiyg.png" /><figcaption>dependencies and react-app-rewired changes in package.json</figcaption></figure><p>With all these dependencies installed, create a new file config-overrides.js in your project’s root folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*v9RAVbaTx08iCm8_RghLbw.png" /><figcaption>config-overrides.js ensures that react-hot-loader is run with create-react-app</figcaption></figure><p>The react-dom alias to @hot-loader/react-dom allows your components’ state to be preserved even when using React 16.8’s hooks such as <a href="https://reactjs.org/docs/hooks-overview.html#state-hook">useState</a>.</p><h3>Export a hot-enabled App module</h3><p>Finally, it’s time to wrap your app’s highest level component with a hot higher-order-component, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*5Yruipe2tdHzGW21oeoaWg.png" /></figure><p>It’s the hot(module)(App) call that makes your app retain state while your components are updated as you make live code changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2c7afe1dae8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>