<?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 Steve Mao on Medium]]></title>
        <description><![CDATA[Stories by Steve Mao on Medium]]></description>
        <link>https://medium.com/@stevemao?source=rss-2a7b7eb4cbfa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DlnGH2qXM2Psj9GY.jpg</url>
            <title>Stories by Steve Mao on Medium</title>
            <link>https://medium.com/@stevemao?source=rss-2a7b7eb4cbfa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 00:57:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stevemao/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[Do not use anonymous functions to construct React functional components]]></title>
            <link>https://medium.com/@stevemao/do-not-use-anonymous-functions-to-construct-react-functional-components-c5408ec8f4c7?source=rss-2a7b7eb4cbfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5408ec8f4c7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Steve Mao]]></dc:creator>
            <pubDate>Sun, 05 Mar 2017 08:39:53 GMT</pubDate>
            <atom:updated>2018-09-12T00:25:04.617Z</atom:updated>
            <content:encoded><![CDATA[<p>We strive to keep our code as concise as possible. If we need a stateless component, its recommended to use a simple functional component. <a href="https://github.com/airbnb/javascript">AirBnB </a><a href="http://eslint.org/">ESLint</a> would error if you don’t do so. However, it’s tempted to write anonymous functional components especially when the component is very simple. Consider the following:</p><pre>// in Foo.js</pre><pre>export default (props) =&gt; (<br>    &lt;div&gt;My component&lt;/div&gt;<br>)</pre><p>It works as expected and there’s probably no linting errors. However, there is no display name on the component by default. The drawbacks are:</p><h3>1. If you use arrow functions, you are not following the class semantics.</h3><p><strong>EDIT: </strong>React components don’t have to be a class or constructor. But it’ll be more verbose if you use <a href="https://twitter.com/dan_abramov/status/838391949975564288">implicit name</a>. Please skip this section.</p><p><a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow function expression</a> is probably one of the most overrated features in ES6. In fact, they cannot be used as constructors. <a href="https://babeljs.io/">Babel</a>, however, transpiles them to normal function expressions which can be used as constructors. Although <a href="https://twitter.com/dan_abramov/status/838391949975564288">it works with implicit name</a>, I believe React components should always follow the class or constructor semantics.</p><pre>// in Foo.js</pre><pre>const Foo = () =&gt; (<br>    &lt;div&gt;My component&lt;/div&gt;<br>)</pre><pre>export default Foo</pre><h3>2. It becomes harder to debug.</h3><p>The display name on React components is a good way to find out the problem when there’s an exception the the console. It also makes it easier to see the component in the React tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*DqHS9DmQDjj1NbIt4F_dCg.png" /></figure><h3>3. It becomes harder to test.</h3><p>Tools like <a href="http://airbnb.io/enzyme/">Enzyme</a> supports <a href="http://airbnb.io/enzyme/docs/api/selector.html">special selectors</a> that can quickly find and test the child wrapper you want. If you don’t use display name, you might have problems. The error messages might be misleading. To those who are new to Enzyme like me, I didn’t even realise the selector was based on the display name, and thanks to jsx, I actually thought it was based on the “tag name”.</p><pre>// in Bar.js</pre><pre>import Foo from &#39;./Foo.js&#39;<br>import { shallow } from &#39;enzyme&#39;</pre><pre>function Bar(props) {<br>    // `Foo` is not a &quot;tag name&quot;<br>    return &lt;Foo /&gt;<br>}</pre><pre>const wrapper = shallow(Bar)<br>wrapper.find(&#39;Foo&#39;) // It won&#39;t find the `Foo` component</pre><p>In conclusion, you should always use the following pattern in simple React functional components:</p><pre>export default function Foo(props) {<br>    return (<br>        &lt;div&gt;My component&lt;/div&gt;<br>    )<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5408ec8f4c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hidden recursion]]></title>
            <link>https://medium.com/@stevemao/hidden-recursion-880bed6ad5a2?source=rss-2a7b7eb4cbfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/880bed6ad5a2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[internet-explorer]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Steve Mao]]></dc:creator>
            <pubDate>Sun, 25 Sep 2016 02:26:56 GMT</pubDate>
            <atom:updated>2017-03-05T08:51:25.670Z</atom:updated>
            <content:encoded><![CDATA[<pre>let flag = false;</pre><pre>function foo() {<br>    if (flag === false) {<br>        flag = true;<br>        // do something<br>        flag = false;<br>    }<br>}</pre><p>What is this pattern? What is the flag doing here? The key part is in “do something”: it may call foo() again! So this is saying “if I am called inside of myself, don’t do something” or “I only wanna do something if I’m not called by myself”. A very good example is in <a href="https://github.com/andreypopp/autobind-decorator/blob/master/src/index.js#L68-L87">autobind-decorator</a>.</p><pre>// In IE11 calling Object.defineProperty has a side-effect of evaluating the<br>// getter for the property which is being replaced. This causes infinite<br>// recursion and an &quot;Out of stack space&quot; error.<br>let definingProperty = false;</pre><pre>return {<br> configurable: true,<br> get() {<br>  if (definingProperty || this === target.prototype || this.hasOwnProperty(key)) {<br>   return fn;<br>  }</pre><pre>let boundFn = fn.bind(this);<br>  definingProperty = true;<br>  Object.defineProperty(this, key, {<br>   value: boundFn,<br>   configurable: true,<br>   writable: true<br>  });<br>  definingProperty = false;<br>  return boundFn;<br> }<br>};</pre><p>It is not very obvious what definingProperty is doing here. In IE11 there is a bug that calling Object.defineProperty would call the getter of the property. So it’s a hidden recursion to IE11.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=880bed6ad5a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I’ve always wanted to write a blog post but writing is definitely not my thing.]]></title>
            <link>https://medium.com/@stevemao/ive-always-wanted-to-write-a-blog-post-but-writing-is-definitely-not-my-thing-e8e0ef8614c5?source=rss-2a7b7eb4cbfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8e0ef8614c5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Steve Mao]]></dc:creator>
            <pubDate>Sun, 25 Sep 2016 00:23:07 GMT</pubDate>
            <atom:updated>2016-09-25T09:49:09.316Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve always wanted to write a blog post but writing is definitely not my thing. However, I believe sometimes I need to step out of my comfortable zone. This article is not about left-pad, but instead, I wanna talk about how I got into open source.</p><p>I have never been a good student at uni. I was struggling with graduating, getting a job, getting my residency in Australia. The immigration law in Australia is stringent, they are just trying to make money from overseas students. At that time, I had to either pass IELTS (English tests) or study so-called Professional Year (a program for foreign workers to learn OZ culture). But unfortunately, they are both bullshit.</p><p>When I was close to 25 years old, I finally started to feel the burden of the society and plan for the future. I did some Unity3D before but it wasn’t popular in OZ, so it was hard to find a job. I started looking at seek.com.au, it looks like web development had the most jobs and JavaScript seemed a lot easier to learn. I heard that people without a computer science degree can do it, and I naively thought I should do better than them :)</p><p>I got a job, everything went fine. A lot of time I just copy/paste some jQuery code from StackOverflow, and it works. One night I was reading <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new">new operator</a> on MDN and the behaviour surprised me; it’s totally different from the new in Java or C#! Since then I try to read/study more, there are a lot of surprising behaviours in JavaScript and I totally got addicted. I swore that one day I need to be able to read and contribute to the jQuery source code just to prove I’m not a noob anymore.</p><p>During Christmas break in 2013, I was browsing and learn some JavaScript frameworks. A few things caught my eyes: Yeoman generators, bower, grunt. They work together like magic. yo webapp and <strong>boom</strong>! A website with live-reload and a lot of goodies are done! Wonderful. But what if I change something in the SASS file? <strong>Boom</strong> the build fails. The build was quite buggy, and I had no idea how to fix it. Node.js docs were so unfriendly to beginners back then. I also learned some good developers like Sindre Sorhus, Paul Irish and <a href="https://addyosmani.com/">Addy Osmani</a> etc. Idolising good developers is not a good thing but setting a goal is.</p><p>But how I got into contributing to them? Well, I started with simple doc fixes. It’s easier to find typos online :p and yeah don’t ever think fixing typos are useless. We need all kinds of contributions. Fixing the docs also means you understand what the lib/framework does. This also means that everyone can do something to contribute to the community! Believe it or not, it’s a very important step! I was then able to fix some simple bugs for yeoman, mostly just some config. Yeah, that’s pretty much how I started!</p><p>Later on, I found a bug in the CHANGELOG of generator-angular, manually fixing it wasn’t a good option, so I dug into it. I was pointed it’s a bug in conventional-changelog. I was encouraged by Sindre that I could ask for push access since it was unmaintained. So I did. Everyone seemed to be very friendly to such a noob like me. I was excited and really wanted to fix all the issues. Fixing them wasn’t easy. In fact, it was a lot harder than I thought! Node.js docs were still terrible! In order to learn more, I had to search through Tweets, StackOverflow, GitHub issue tracker. Information is all scattered around!</p><p>About a year after I maintained conventional-changelog, I looked into code base such as jQuery, and surprised that I could understand a lot more than before, even improving it! I finally achieved my childhood dream :) I also connected with Paul Irish on the diff-so-fancy project, and I wouldn’t think this was possible. Feeling like a dream.</p><p>I started programming relatively later than most open source developers, but I never regretted. It’s the best thing in my life and I’m blessed with good career and friends.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8e0ef8614c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>