<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Wei Gao</title>
    <description>The latest articles on Forem by Wei Gao (@wgao19).</description>
    <link>https://forem.com/wgao19</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F111879%2Feed1414c-7160-4b4e-9fed-1e72ef8312da.jpg</url>
      <title>Forem: Wei Gao</title>
      <link>https://forem.com/wgao19</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wgao19"/>
    <language>en</language>
    <item>
      <title>Animated CSS Blob</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Thu, 07 Jan 2021 10:56:14 +0000</pubDate>
      <link>https://forem.com/wgao19/animated-css-blob-cnp</link>
      <guid>https://forem.com/wgao19/animated-css-blob-cnp</guid>
      <description>&lt;p&gt;I'm a pure blob over the holidays these days, so I decided to make something blobby on &lt;a href="https://aworkinprogress.studio/" rel="noopener noreferrer"&gt;my website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is this blob:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F0negrqL.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F0negrqL.gif" alt="animated css blob"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://css-tricks.com/blobs/" rel="noopener noreferrer"&gt;quite a few ways you can create blobs on the web&lt;/a&gt;. But following the blobby attitude I've chosen the simplest technology – CSS border radius – one that I can wrap my brain around with, to be the main recipe for this blob. Overall, it'll still be a few simple techniques put together that I'll briefly list out in this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS border radius
&lt;/h2&gt;

&lt;p&gt;The key to the irregular shape is to make use of the power of border radius. Not only can you specify each corner, but also you can supply pairs of values such that each corner can take different border radii so that it looks skewed towards one direction or the other.&lt;/p&gt;

&lt;p&gt;Here's a video showing its mechanism from Robin Rendle's &lt;a href="https://css-tricks.com/css-border-radius-can-do-that/" rel="noopener noreferrer"&gt;post&lt;/a&gt;:&lt;/p&gt;



&lt;p&gt;The video is taken from &lt;a href="https://9elements.github.io/fancy-border-radius/" rel="noopener noreferrer"&gt;fancy-border-radius&lt;/a&gt; that you can use to play around with the shape defined by those border radii.&lt;/p&gt;

&lt;p&gt;Generally speaking, the smaller the percentage value, the sharper it will look at the point the blob touches its bounding box. I want my blob to look fairly rounded so I've taken fairly large values in those radii. And to get the curves to have a smooth join, it's worth to make the percentage values complement to each other in pairs – and fewer random numbers needed to generate as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Animation
&lt;/h2&gt;

&lt;p&gt;I've used simple keyframes for the animation. My blob is quite slow, it's 7s animation on alternate direction &amp;amp; infinite loop. I've also made them spin a little bit by adding a &lt;code&gt;transform: rotate()&lt;/code&gt; to the animation frames.&lt;/p&gt;

&lt;p&gt;Also, to add some randomness I've generated the animation when component mounts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blending
&lt;/h2&gt;

&lt;p&gt;As you can see, the blobs created by CSS border radius will be all convex, the shape a bit simple. To add some flavor to it, I've recalled my &lt;code&gt;mix-blend-mode&lt;/code&gt; magic (you can read about it in my other post &lt;a href="//../sun-moon-blending-mode/"&gt;about CSS &lt;code&gt;mix-blend-mode&lt;/code&gt;&lt;/a&gt;). Namely, I've created three blobs with slightly different shades of grey and some offset in their &lt;code&gt;animation-delay&lt;/code&gt;, and made them &lt;code&gt;mix-blend-mode: luminosity&lt;/code&gt; with one another.&lt;/p&gt;

&lt;p&gt;When you enlarge them they look pretty sick, I think:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FRcMCCRy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FRcMCCRy.gif" alt="the wavy edge of the blobs"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Putting them altogether, here's one of the generated animation CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.blob&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;blobby&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-iteration-count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-timing-function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;mix-blend-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;luminosity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;blobby&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;20&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;41%&lt;/span&gt; &lt;span class="m"&gt;59%&lt;/span&gt; &lt;span class="m"&gt;41%&lt;/span&gt; &lt;span class="m"&gt;59%&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="m"&gt;53%&lt;/span&gt; &lt;span class="m"&gt;51%&lt;/span&gt; &lt;span class="m"&gt;49%&lt;/span&gt; &lt;span class="m"&gt;47%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;36deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;40&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;72deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;43%&lt;/span&gt; &lt;span class="m"&gt;57%&lt;/span&gt; &lt;span class="m"&gt;41%&lt;/span&gt; &lt;span class="m"&gt;59%&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="m"&gt;53%&lt;/span&gt; &lt;span class="m"&gt;52%&lt;/span&gt; &lt;span class="m"&gt;48%&lt;/span&gt; &lt;span class="m"&gt;47%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;80&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;48%&lt;/span&gt; &lt;span class="m"&gt;52%&lt;/span&gt; &lt;span class="m"&gt;41%&lt;/span&gt; &lt;span class="m"&gt;59%&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="m"&gt;48%&lt;/span&gt; &lt;span class="m"&gt;58%&lt;/span&gt; &lt;span class="m"&gt;42%&lt;/span&gt; &lt;span class="m"&gt;52%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;108deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;144deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;54%&lt;/span&gt; &lt;span class="m"&gt;46%&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt; &lt;span class="m"&gt;40%&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="m"&gt;43%&lt;/span&gt; &lt;span class="m"&gt;55%&lt;/span&gt; &lt;span class="m"&gt;45%&lt;/span&gt; &lt;span class="m"&gt;57%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a few more CSS properties such as each of the blobs' &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;animation-delay&lt;/code&gt;, you can inspect them in my site &lt;a href="https://aworkinprogress.studio/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>css</category>
    </item>
    <item>
      <title>Rethinking React Knowledgeable</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Tue, 06 Oct 2020 14:44:23 +0000</pubDate>
      <link>https://forem.com/wgao19/rethinking-react-knowledgeable-1h80</link>
      <guid>https://forem.com/wgao19/rethinking-react-knowledgeable-1h80</guid>
      <description>&lt;p&gt;Last week marks the second full year for me and &lt;a href="//twitter.com/kenleesm"&gt;Ken Lee&lt;/a&gt; to have run &lt;a href="https://twitter.com/reknowledgeable"&gt;React Knowledgeable&lt;/a&gt;, for Shopee and the local developer community combined. Altogether &lt;a href="https://github.com/Shopee/shopee-react-knowledgeable/issues?q=is%3Aissue+label%3Atalk"&gt;we have 85 weeks at the back of our memory&lt;/a&gt;. And, unexpectedly or not, at this two year mark, we've decided to change it to something completely different, project code &lt;code&gt;rk-next&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There are a few causes that could seem quite obvious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the conference / meetup scene is significantly disturbed by the COVID-19 situation this year&lt;/li&gt;
&lt;li&gt;as most of us are working from home semi-regularly, we interact with each other much less that used to inspire many thoughts and ideas for sharing&lt;/li&gt;
&lt;li&gt;this could be personal but I feel it is overall more stressful to work from home and alone, and therefore less willing to prepare a sharing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although, if only for the reasons above, there are ways other than a radical reform to adapt to the situation. For example, we could fallback to the luckydraw system. Or, we could drop the frequency. We could even pause for longer until things start to recuperate.&lt;/p&gt;

&lt;p&gt;But, there are also a few more reasons that pushed me to rethink RK at this time:&lt;/p&gt;

&lt;p&gt;Now that we have a much larger team, how much participation does each of us get, if we continue to run it as a weekly sharing where 1 person gets the podium? And more practically, do myself and Ken have enough capacity to run it, if we keep scaling it up?&lt;/p&gt;

&lt;p&gt;What do we really want to get out of a weekly sharing? What do we want on a deeper level? Can RK help the true cause in any other format that fits the current situation better?&lt;/p&gt;

&lt;h1&gt;
  
  
  Rethinking RK
&lt;/h1&gt;

&lt;p&gt;At this two-year mark, I'll share those questions I've been thinking of for the past two months, and invite those of you who are in the loop of RK, to join me for a bit of discussion on what we just started recently -- &lt;em&gt;RK in Rosters&lt;/em&gt;, where we break into small and private groups, and commit to the roster for a fixed period of time. The rosters are proposed and run by some of us who will take the lead and say, "let's do this." Despite how semi-well-thought-of it seems right now, please still question it, experiment with it, and most importantly, feel if and how you'd like it to be a part of your weekly routine, at least for the time being. Exactly like two years ago we're creating something completely original of our own, and so everyone of us may take a part of it and have the power of shaping it to something you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do we want to keep scaling up like a conference, or do we want a smaller learning group?
&lt;/h2&gt;

&lt;p&gt;This is a pseudo question. The RK in Roster proposal is our answer to this question already, but let me still share why.&lt;/p&gt;

&lt;p&gt;The moment I realize our audience size as it is intended for, it was a near instant signal that we need something different. Before we even called it RK, the best team weekly I had been part of was the "this week I learned" section that used to occupy the current RK hour, for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it was the most relaxing hour of the week&lt;/li&gt;
&lt;li&gt;we were comfortable with one another in the team&lt;/li&gt;
&lt;li&gt;it was a very good recap of the week, a raincheck that we're learning, an opportunity to revisit the problem and sharpen the understanding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that our audience size is reaching a mini conference, it deviates so far away from the original, cozy, relaxed and content-focused sharing podium, that I had to re-start the same initiative within a 4-person team that I had the brief fortune to lead, for the past few months. Then, as one of the organizers for RK I'd ask, can I bring the similar experience back?&lt;/p&gt;

&lt;h2&gt;
  
  
  Should it be topic-based or people-based?
&lt;/h2&gt;

&lt;p&gt;I've been with Shopee for close to 4 years now. There are many people who I have worked with and enjoyed the accompany with. The 6 people in my original team are working in different teams / groups now. But I still want to be in close proximity with them and would like to occasionally catch up to see what each other is working on.&lt;/p&gt;

&lt;p&gt;I find RK fits a right scope for the right time for this. Developers from our few front end teams don't work with each other on a daily basis. Within RK's scope, but cross each of our feature line teams and groups, why don't we give our ourselves a cause to regularly and semi-casually catch up with one another, especially with those who we don't directly work with, and together work on or share front end things.&lt;/p&gt;

&lt;p&gt;That's why, at the back of my mind, I really want people to group up based on who you enjoy the talking with. It's a mindset shift. I observe that now people are hosting and joining groups mainly based on topics. They're very attractive, especially before we know each other so well to have some blind faith, topics are the only tangible cause for people to decide to join. On the flip side, I really want to propose that we run some more relaxed, people-based groups that don't set a specific topic. We come in and see what other people are working on lately and let ideas flow.&lt;/p&gt;

&lt;p&gt;Some of the rosters now are assignment-based. They're very interesting. We send out a goal / assignment at the beginning of each week, and we find our own time to explore a bit about it, and we come back at the end of the week for a discussion. In essence it's still based on a topic but we call for more participation by inviting you to work on something.&lt;/p&gt;

&lt;p&gt;What's your preference?&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the learning process that RK should highlight?
&lt;/h2&gt;

&lt;p&gt;Learning and exploring is a popular initiative in our industry. But to me and my perspectives on RK, I think the learning process should not narrowly focus on the mere intake of new technology from other people.&lt;/p&gt;

&lt;p&gt;The Shopee app that we are collectively building has many enough questions to push us to see how other people are solving similar problems, decide whether they will solve our problems, and come up with our own solutions when necessary. This sometimes is happening on a very significant level, like some of us are building some very complex systems to make pieces of our code function together. But note that it certainly happens on a micro level and the major renovation is an iterative process of explorations, trials and errors, asking questions, asking better questions, attempting to answer them, and revisiting and recapitulating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;iterate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;explore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;trialAndError&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;askQuestion&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;answerQuestion&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oops, wrong liao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;recapitulate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;iterate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Previously, RK participates at the very end of this process. &lt;em&gt;After&lt;/em&gt; you learned something, we encourage you to share your thoughts. Today, RK takes a step forward and invites you to take part of this messy, uncertain, and only sometimes rewarding process, one where we urge you to bake into your weekly routine to look back and see if you've put your minds on something worth mentioning, even just to yourself, over the past week.&lt;/p&gt;

&lt;h1&gt;
  
  
  How it works
&lt;/h1&gt;

&lt;p&gt;We host &lt;em&gt;RK in Rosters&lt;/em&gt; in terms of 8 weeks. Each term, you may either host or join a roster. We will intermittently run one or two community events when we invite everyone back for a to share our progresses thoughts, and we go back to the regular term sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What RK asks of you
&lt;/h2&gt;

&lt;p&gt;There are only two things that we (sort of) require that you do:&lt;/p&gt;

&lt;p&gt;One, &lt;strong&gt;participate non trivially&lt;/strong&gt;. In the old RK, speakers prepare sharing topics and audiences sit back and listen. This is not interesting (enough), if you haven't realized, by giving a sharing yourself.&lt;/p&gt;

&lt;p&gt;Two, &lt;strong&gt;commit to your same group of people for the whole duration of each term&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And in return, RK allows you to switch around with no strings attached, by running all rosters &lt;em&gt;in terms of 8 weeks&lt;/em&gt;. If there's anything you don't enjoy, you realize you hate someone, etc., note that it'll end in 8 weeks. And if you really enjoy what your roster is doing, great, you can make it happen again in the next term.&lt;/p&gt;

&lt;h1&gt;
  
  
  What this really is
&lt;/h1&gt;

&lt;p&gt;...is that we are developers who love to explore, and among us a few would like to take the responsibilities to lead a direction. RK sets the game rule, but it's pointless if not for the hosts who will lead the experience, and for the participants who find it meaningful.&lt;/p&gt;

&lt;h1&gt;
  
  
  FAQs
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;If I host a roster, does that mean I forever cannot join other rosters?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can choose to host your rosters at alternating terms. Or, you can help someone in your roster to become a future host :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I'm really interested in this topic, but I am unsure about the commitment it takes to join&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please don't let this stop you from joining. We understand that each of us has work commitments that should take priorities and the roster hosts won't judge you for not making progresses on occasional weeks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will there be a roster on X?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please start one :) We'll help you get started with hosting&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will there be no regular RKs anymore T_T?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll host joint events at a longer interval, monthly or every two months.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will joint events take only roster sharing topic?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No, please still submit sharing if you have anything outside of your roster (or if you're not in any roster) that you want to share.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it internal T_T?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For the time being, the Rosters are internal. If you like the idea, there are other initiatives that share some similar thoughts, such as the &lt;a href="https://kentcdodds.com/clubs/"&gt;KCD Learning Clubs&lt;/a&gt; (thanks &lt;a href="https://twitter.com/lihautan"&gt;@lihautan&lt;/a&gt; for referring). If ours work well, we might see how we can help build similar things in the local community.&lt;/p&gt;

&lt;p&gt;The community events &lt;em&gt;will be&lt;/em&gt; open to the public.&lt;/p&gt;

</description>
      <category>community</category>
      <category>learning</category>
    </item>
    <item>
      <title>Play with React Concurrent Mode with Your Gatsby Site [updated with more proper solution]</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Mon, 28 Oct 2019 16:06:43 +0000</pubDate>
      <link>https://forem.com/wgao19/play-with-react-concurrent-mode-with-your-gatsby-site-2b70</link>
      <guid>https://forem.com/wgao19/play-with-react-concurrent-mode-with-your-gatsby-site-2b70</guid>
      <description>&lt;p&gt;So the React team released &lt;a href="https://reactjs.org/docs/concurrent-mode-intro.html" rel="noopener noreferrer"&gt;curious cat version for concurrent mode&lt;/a&gt;, and I want to try that with my personal sites and side projects, only to realize that by using Gatsby I do not have direct access to my &lt;code&gt;ReactDOM.render()&lt;/code&gt;, which I am supposed to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Put in your &lt;code&gt;gatsby-browser.js&lt;/code&gt; the following:&lt;/p&gt;

&lt;p&gt;Solution by &lt;a href="https://twitter.com/EphemeralCircle" rel="noopener noreferrer"&gt;Fredrik Höglund&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// gatsby-browser.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceHydrateFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;hydrate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;hydrationOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onHydrated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;p&gt;A quick search landed me on &lt;a href="https://github.com/gatsbyjs/gatsby/issues/13675" rel="noopener noreferrer"&gt;this issue&lt;/a&gt;, which brings me to &lt;a href="https://www.gatsbyjs.org/docs/browser-apis/" rel="noopener noreferrer"&gt;Gatsby's Browser APIs&lt;/a&gt;. And in particular, its &lt;a href="https://www.gatsbyjs.org/docs/browser-apis/#replaceHydrateFunction" rel="noopener noreferrer"&gt;&lt;code&gt;replaceHydrateFunction&lt;/code&gt;&lt;/a&gt;. This function is meant for customized hydration on SSR. It just so happens that it becomes our chance to swap out the &lt;code&gt;ReactDOM.render()&lt;/code&gt; call. &lt;a href="https://github.com/gatsbyjs/gatsby/blob/ebff3153364974a3893b3c943b311c03868b8fcb/packages/gatsby/cache-dir/production-app.js#L152" rel="noopener noreferrer"&gt;Gatsby will call what we return as the replacement&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceHydrateFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rendering!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And from React's official docs on Concurrent Mode, this is what we should change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// If you previously had:&lt;/span&gt;
&lt;span class="c1"&gt;// ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById('root'));&lt;/span&gt;
&lt;span class="c1"&gt;// You can opt into Concurrent Mode by writing:&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My initial attempt was to write my tweak like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceHydrateFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works. But on local build only. On production build, my page content gets duplicated, as you can see &lt;a href="https://deploy-preview-59--react-knowledgeable.netlify.com" rel="noopener noreferrer"&gt;in this preview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/.%2Fduplicated%2520dom%2520on%2520production%2520build.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/.%2Fduplicated%2520dom%2520on%2520production%2520build.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;del&gt;Out of my amateurish understanding around Gatsby, this looks like a &lt;a href="https://www.gatsbyjs.org/docs/production-app/#dom-hydration" rel="noopener noreferrer"&gt;DOM hydration&lt;/a&gt; issue. I now have a blurry understanding about why this following code works, but I probably should not be misleading people. If anybody has a better understanding, please &lt;a href="https://twitter.com/wgao19" rel="noopener noreferrer"&gt;teach me&lt;/a&gt; 🙆🏻‍♀️&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;I later on realize the problem was probably due to not calling &lt;code&gt;ReactDOM.hydrate&lt;/code&gt;, which is supposed to be the default behavior. Below has been updated to &lt;em&gt;some&lt;/em&gt; code that works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceHydrateFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hydrate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But &lt;a href="https://twitter.com/EphemeralCircle" rel="noopener noreferrer"&gt;Fredrik Höglund&lt;/a&gt; pointed out that this is problematic, because&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In legacy mode, ReactDOM.render and ReactDOM.hydrate are two separate functions. In concurrent mode, there is only one function, ReactDOM.createRoot, but with an option for hydrate.&lt;br&gt;
&lt;a href="https://github.com/facebook/react/blob/f6b8d31a76cbbcbbeb2f1d59074dfe72e0c82806/packages/react-dom/src/client/ReactDOM.js#L619" rel="noopener noreferrer"&gt;Src if curious&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So a more proper fix will be as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceHydrateFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;hydrate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;hydrationOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onHydrated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you can &lt;a href="https://twitter.com/EphemeralCircle/status/1190671700645597184?s=20" rel="noopener noreferrer"&gt;check out the twitter discussion&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  More notes
&lt;/h2&gt;

&lt;p&gt;Don't read these.&lt;/p&gt;

&lt;h3&gt;
  
  
  When and how does Gatsby call &lt;code&gt;render&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;It calls the &lt;code&gt;renderer&lt;/code&gt; which is the return of &lt;code&gt;replaceHydrateFunction&lt;/code&gt;, defaults to &lt;code&gt;ReactDOM.hydrate&lt;/code&gt;. Then, it will call &lt;code&gt;onInitialClientRender&lt;/code&gt;, which is the third parameter, &lt;code&gt;callback&lt;/code&gt;, in the return function of &lt;code&gt;replaceHydrateFunction&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does &lt;code&gt;ReactDOM.hydrate&lt;/code&gt; do in a Gatsby site?
&lt;/h3&gt;

&lt;p&gt;According to the &lt;a href="https://www.gatsbyjs.org/docs/production-app/#dom-hydration" rel="noopener noreferrer"&gt;Gatsby documentation on DOM hydration&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://reactjs.org/docs/react-dom.html#hydrate" rel="noopener noreferrer"&gt;&lt;code&gt;hydrate()&lt;/code&gt;&lt;/a&gt; is a &lt;a href="https://reactjs.org/docs/react-dom.html" rel="noopener noreferrer"&gt;ReactDOM&lt;/a&gt; function which is the same as &lt;code&gt;render()&lt;/code&gt;, except that instead of generating a new DOM tree and inserting it into the document, it expects that a React DOM already exists with exactly the same structure as the React Model. It therefore descends this tree and attaches the appropriate event listeners to it so that it becomes a live React DOM. Since your HTML was rendered with exactly the same code as you're running in your browser, these will (and have to) match perfectly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Checking our Gatsby site's &lt;code&gt;public&lt;/code&gt; directory, those are some uglified HTMLs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The hydration occurs on the &lt;code&gt;&amp;lt;div id="___gatsby"&amp;gt;...&amp;lt;/div&amp;gt;&lt;/code&gt; element defined in &lt;a href="https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/default-html.js#L21" rel="noopener noreferrer"&gt;default-html.js&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But I still don't understand what caused the duplication above -.- It duplicates the child element of &lt;code&gt;&amp;lt;div id="___gatsby"&amp;gt;...&amp;lt;/div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens if the DOM isn't properly hydrated or &lt;code&gt;onInitialClientRender&lt;/code&gt; isn't properly called?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;event handlers don't get attached&lt;/li&gt;
&lt;li&gt;css-in-js doesn't get inserted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;maybe more&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/concurrent-mode-adoption.html" rel="noopener noreferrer"&gt;Adopting Concurrent Mode (Experimental)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/gatsbyjs/gatsby/issues/13675" rel="noopener noreferrer"&gt;Extend BrowserApi for React Concurrent Mode #13675&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.org/docs/browser-apis/#replaceHydrateFunction" rel="noopener noreferrer"&gt;GatsbyJS Browser API &lt;code&gt;replaceHydrateFunction&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.org/docs/html-generation/#7-render-final-html-document" rel="noopener noreferrer"&gt;Gatsby HTML hydration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/react-dom.html#hydrate" rel="noopener noreferrer"&gt;ReactDOM hydrate doc&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/EphemeralCircle/status/1190671700645597184?s=20" rel="noopener noreferrer"&gt;twitter thread about this&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>gatsby</category>
    </item>
    <item>
      <title>Re-export Context Provider</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Wed, 23 Oct 2019 03:43:44 +0000</pubDate>
      <link>https://forem.com/wgao19/re-export-context-provider-10c3</link>
      <guid>https://forem.com/wgao19/re-export-context-provider-10c3</guid>
      <description>&lt;p&gt;Recently I realize I like this pattern a lot, much enough that I'll write a short note on this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;When we use React's Context​, we need to first create the context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ContextA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;&amp;lt;Context.Provider /&amp;gt;&lt;/code&gt; is normally called elsewhere. We'd probably import the context, grab the named Provider​ inside, and mount that &lt;code&gt;&amp;lt;Provider /&amp;gt;&lt;/code&gt;​ with a value​ that we as a user needs to know. And likely higher in our component tree we have many of these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PlaylistContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mySpotifyPlaylist&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CoffeeContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;morning&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;americano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flatwhite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;WorkspaceContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        ...now i can start working
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;WorkspaceContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;CoffeeContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;PlaylistContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;What makes more sense to me is that the developer who works on the Context probably knows all the things about it. Here is something I learned from &lt;a href="https://github.com/jamiebuilds/unstated-next"&gt;Jamie's hook-based Unstated library&lt;/a&gt;. Instead of exporting the bare bone Context​, we can wrap and re-export the context provider. This allows the author of the context to keep all the logic along the same conceptual object in one place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PlaylistContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PlaylistProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// potentially code to create "value"&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;playlist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bach Cello Suite No.1 in G Major, BWV1007&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PlaylistContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;playlist&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;PlaylistContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now in our app root, or anywhere we need to use the context, we no longer need to generate and supply that value elsewhere. We can write very terse context providers like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PlaylistProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CoffeeProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;WorkspaceProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;...my day of work&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;WorkspaceProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;CoffeeProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;PlaylistProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are with TypeScript and have complaints around annotating the context value with a potential &lt;code&gt;null&lt;/code&gt; when creating the context, check out &lt;a href="https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#context"&gt;this solution in React TypeScript Cheatsheet&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Relevant links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jamiebuilds/unstated-next"&gt;Jamie's hook-based Unstated library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#context"&gt;make a &lt;code&gt;createCtx&lt;/code&gt; and make TypeScript happy with no &lt;code&gt;defaultValue&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Properly Include Component Function from `useEffect` and `useCallback` Dependency List</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Sun, 13 Oct 2019 06:19:33 +0000</pubDate>
      <link>https://forem.com/wgao19/properly-include-component-function-from-useeffect-and-usecallback-dependency-list-4m3o</link>
      <guid>https://forem.com/wgao19/properly-include-component-function-from-useeffect-and-usecallback-dependency-list-4m3o</guid>
      <description>&lt;p&gt;I was working on &lt;a href="https://codesandbox.io/s/slots-3q0ks"&gt;Slots&lt;/a&gt; (letting a portal component render into a potentially not mounted portal home) when initially I was violating a &lt;a href="https://reactjs.org/docs/hooks-rules.html"&gt;hooks rule&lt;/a&gt;. Namely, I did not include the &lt;code&gt;setSlot&lt;/code&gt; function I called within the &lt;code&gt;useCallback&lt;/code&gt; body inside its dependency list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SlotHome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;slotName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="nx"&gt;setSlot&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSlot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slotName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// we're lying to hooks because we're using setSlot without including it in the deps list&lt;/span&gt;
    &lt;span class="nx"&gt;setSlot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But if I do include it, the function is different every time the component render is called and therefore would re-render like a maniac. Without including it, the implementation still works, but we're lying to hooks and it is &lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/#dont-lie-to-react-about-dependencies"&gt;strongly advised against&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This made me finally decided (cuz it says it's a 49-min read) to read Dan Abramov's article, &lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;A Complete Guide to &lt;code&gt;useEffect&lt;/code&gt;&lt;/a&gt; and decided to properly figure this out. Here are some key takeaways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;class components mutate state&lt;/li&gt;
&lt;li&gt;functional components + hooks retain the proper closure behavior (always use closed variable, no mutating crap)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;3 ways to optimize dependency list&lt;/em&gt;

&lt;ul&gt;
&lt;li&gt;remove unnecessary use of params in component lifecycle scope&lt;/li&gt;
&lt;li&gt;use reducer&lt;/li&gt;
&lt;li&gt;&lt;em&gt;memoize functions with &lt;code&gt;useCallback&lt;/code&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The highlighted takeaway was what solved this problem. The idea is to tell hooks that the function won't change unless what we specify in that &lt;code&gt;useCallback&lt;/code&gt;'s dependency list change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="nx"&gt;setSlot&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSlot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slotName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// specify that setSlotMemo won't change unless slotName changes&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setSlotMemo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setSlot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;slotName&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;// now ref is safe to include setSlotMemo in its deps list&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setSlotMemo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;setSlotMemo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once again Dan's article covers a complete guide to properly use &lt;code&gt;useEffect&lt;/code&gt; (which extends to &lt;code&gt;useCallback&lt;/code&gt; because they share the same signature).&lt;/p&gt;

&lt;h2&gt;
  
  
  Relevant links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/slots-3q0ks"&gt;Slots CodeSandbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;A Complete Guide to &lt;code&gt;useEffect&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/hooks-rules.html"&gt;Rules of Hooks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>4 Years as Front End</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Sat, 12 Oct 2019 14:49:23 +0000</pubDate>
      <link>https://forem.com/wgao19/4-years-as-front-end-1a4</link>
      <guid>https://forem.com/wgao19/4-years-as-front-end-1a4</guid>
      <description>&lt;p&gt;Today (Sept 8, 2019) marks the 4th year anniversary of my working full time as a front end developer. Before this, I've never done anything consistently past two years other than my college major. I also find some interesting alignment with a college life so here's a personal chronicle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Year 1
&lt;/h2&gt;

&lt;p&gt;In the summer of 2015, I passed the interview to my previous company out of my amateurish knowledge from making webpages since I was a kid. It was the time when jQuery was still a thing but was getting implemented into browser APIs, template based front end frameworks were big, and some early adopters were trying out Vue and React.&lt;/p&gt;

&lt;p&gt;One thing that left an impression was my first encounter with Vue. The guy sitting next to me handed me a project that was due on the second day (literally, I don't know how that could even be remotely possible today). He said that the project was set up in Vue and it should be an easy two-hour thing. Did he not know it was my first time using Vue, or anything at all other than jQuery? I forgot how I ended up making everything work and had it delivered.&lt;/p&gt;

&lt;p&gt;On a similar note, it was a very immature year for me. I had no methodology, no choices of frameworks, and no tastes at all. I followed whatever that was in the codebase.&lt;/p&gt;

&lt;p&gt;I &lt;em&gt;loved&lt;/em&gt; the job, though. I enjoyed the playfulness. To me assembling pages from PRD, design specs, and back end API documentation was exactly like playing &lt;a href="https://www.lego.com/en-us"&gt;Lego&lt;/a&gt;. And I had a day job getting paid doing that. Can't dream about anything more.&lt;/p&gt;

&lt;p&gt;Another aspect of that job was its comprehensiveness. All my projects involved three ends, a consumer-based web app, a business facing PC site, as well as an internal CMS. So I had the opportunity to explore all those platforms, meaning a large aspect of what counts as front end was covered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yOWfbNY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.imgur.com/1NJOI6I.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yOWfbNY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.imgur.com/1NJOI6I.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
One of my "freshman" project had a cute interaction that I liked a lot.



&lt;p&gt;The environment wasn't very promising for technical advancement though. The department did not have much idea where to go. Then at some point of time the whole department shut down. There was some more drama going on and I'm glad I learned early that I'd prefer to steer clear from dramas, disputes, gates and stuff.&lt;/p&gt;

&lt;h2&gt;
  
  
  Year 2
&lt;/h2&gt;

&lt;p&gt;I joined my current team shortly into my second year. The process was somewhat amusing. I was reading books about JavaScript about half a year into year 1. Pumping up theoretical knowledge gave me a false illusion that I could pass any interview already. Then a recruiter contacted me and asked if I'd like to consider a position based in Singapore and that the interview would be &lt;em&gt;very challenging&lt;/em&gt;. I was intrigued both by the relocation as well as wanted to see if my book reading was fruitful or not. So I went with the interview.&lt;/p&gt;

&lt;p&gt;The interviewer has the most hatred generating way of interviewing. He asks increasingly difficult problems until beyond what the interviewee can solve, then he tries to see the potential from there. For me it seemed a bit &lt;em&gt;way beyond&lt;/em&gt;. Since I could answer probably 2 out of the 7 questions he asked, I thought I had pathetically failed. But he hired me on the basis that I said I liked front end and he believed that as long as you like it, you'd sooner or later become very good.&lt;/p&gt;

&lt;p&gt;When I then joined this team, everyone but myself had a CS degree and they were all good to the level I could not evaluate. We were a team of 6 supporting all our web apps across PC and mobile browsers. I started saying that it is the best team I've ever worked with, although I didn't consider myself to be part of it.&lt;/p&gt;

&lt;p&gt;It may sound weird but it was also the first time I maintain a codebase with other people. I had to understand other people's code routinely. And I needed to make sure my code is comprehensible.&lt;/p&gt;

&lt;p&gt;In college I was very hooked up with a math / cs project called &lt;a href="https://projecteuler.net/"&gt;Project Euler&lt;/a&gt;, in which ingenius solutions were something you'd be proud of. Then in the beginning of me getting serious about coding, I liked to write very abstractly mathematical code. I remember I once wrote an algorithm that casts two dimensional values into one string for easier computation in binary. My leader didn't agree with it but I insisted. After a while I started to sense the extra burden to carry such solutions and started to appreciate the code nicely said.&lt;/p&gt;

&lt;p&gt;I was also picking up React mainly by following other people's code. Writing lifecycle methods for web pages seemed a bit unnatural to me (I still don't like the idea, I feel it's too much of a software engineering thing brought to the web arena). I also didn't understand all the Redux boilerplate and whatever pattern that Redux Saga uses, so I asked the team lead "how did you come up with this", and he said he didn't come up with it, it's "standard". Clearly that's a wrong question to ask but that was where I roughly rounded.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ty4EPjeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ePYBtec.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ty4EPjeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ePYBtec.jpg" alt="I enjoy decorating my workspace with postcards. But as the wall of my current company is very small, there is no room for postcards. So I changed to occasionally doodling on my name tag."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Year 3
&lt;/h2&gt;

&lt;p&gt;I think I have a gist on intuition but am very bad at implementation. And frankly, I didn't know how to improve. So year 3 was a serious doubt on my proficiency at the job. I think there are three levels:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Failing it&lt;/li&gt;
&lt;li&gt;No complaint, but nothing great neither&lt;/li&gt;
&lt;li&gt;Absolutely beyond expectation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think there are people born with the right skill set for the subject matter and they enter the field and directly achieve 3 from entry level. Sadly, with software development, I was barely moving away from 1. But that actually wasn't all that bad. I think what is worse is to get stuck at 2.&lt;/p&gt;

&lt;p&gt;2 is a phase where you get comfortable with your day-to-day job. I became familiar with our codebase. I could do my job just alright. I sometimes read other people's code and figured there was no way I could write code like that. But I didn't know what I could do to become better.&lt;/p&gt;

&lt;p&gt;2 is also the worst phase in a sense that people cannot blame you. You've made no mistakes. There were a few 1-1's that went very badly because my managers were expecting more from me and the way we communicated made me think they were blaming me. I think I ended up crying a few times. I also had a long doubt that since the industry has changed so much from the first time I playfully created web pages (year 2000?), maybe I was making a wrong career choice, it's a different job now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5LDN6UNH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/QMt4Va4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5LDN6UNH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/QMt4Va4.jpg" alt="year 3 name tag"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my spare time, I developed a catching interest in climbing. Climbing taught me &lt;a href="https://en.wikipedia.org/wiki/Practice_(learning_method)"&gt;deliberate practice&lt;/a&gt; and has made me used to trying out problems that slightly intimidate me. There's great joy if you get a hard problem down, especially if after consistent training and thoughtful planning. In fact it has such a profound impact in me I could no longer be satisfied living my life any other way. I realized I wasn't doing this in my job, then. It was more than boring compared to what I was doing in climbing.&lt;/p&gt;


&lt;div class="instagram-position"&gt;
  &lt;iframe id="instagram-liquid-tag" src="https://www.instagram.com/p/Bu86nlfFE5g/embed/captioned"&gt;
  &lt;/iframe&gt;
  
&lt;/div&gt;

  
  My recent longest bouldering project, took me a good two months to figure out, many gym visits if not more, many more movement exercises in my other trainings. This post is a work in progress missing the last move, the final send is in another post but I tend to like the wip ones better :)
  





&lt;p&gt;Back to the not-much-to-be-said year 3, it kind of tailed into year 4 with me looking for inspirations by going to &lt;a href="https://reactjs.org/community/conferences.html"&gt;a conference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XeqMjCa_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/KcPoAcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XeqMjCa_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/KcPoAcn.png" alt="stickers from React Rally 2018"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Year 4
&lt;/h2&gt;

&lt;p&gt;I feel more has happened in year 4 than all previous 3 years combined. I have also gained a little bit of exposure throughout the past year. I normally do not present myself very well as I find little motivation in justifying the things I do. Let results speak for themselves, or so I think. But I guess since more people are willing to hear what I have to say, I entitle myself to share a little bit of what I believe could be the most critical moments for myself.&lt;/p&gt;

&lt;p&gt;I met &lt;a href="https://twitter.com/acemarke/"&gt;Mark Erikson&lt;/a&gt; after &lt;a href="https://2018.reactrally.com/"&gt;React Rally 2018&lt;/a&gt;, who had me work on &lt;a href="https://react-redux.js.org/"&gt;React Redux docs&lt;/a&gt;. It's a true gem in learning that I understand only in retrospect. Writing docs puts anybody on the side of "teaching", which requires a completely different level of understanding. The knowledge doesn't flow in automatically, though. You'd still need to dig in the sourcecode yourself. But people play Lego to enjoy the process of assembling them, not to look at the final product right? And so writing docs provides a similar ground for learning in that sense. Meanwhile, Mark has helped me with more than multiple rounds of revisions, from which I've learned a million things about both Redux and React. He has also been promoting the work I've done at all chances for which I am forever grateful about.&lt;/p&gt;

&lt;p&gt;I then worked on many more docs, of which some more substantial work includes &lt;a href="//https:/bdocusaurus.io/"&gt;Docusaurus&lt;/a&gt; and our internal manual. I now have a lot of faith in docs. In a simple manner, I'll normally believe in whatever said in the docs myself. Furthermore, if the answer people are looking for is well said in the official docs, it saves their time because they don't need to look elsewhere. So that's a unique golden place to have in mind. For me docs are also the best opportunities to &lt;a href="https://www.swyx.io/writing/learn-in-public"&gt;#learnInPublic&lt;/a&gt;. Even if a question may already have been answered everywhere, the work and thoughts to organize them into a Q&amp;amp;A entry to fit the context of the official docs is non-trivial. Plus you'd get multiple eyes for revisions, and the outcomes are very valuable (see previous point).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m2CLmnDI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FqODdkB.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m2CLmnDI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FqODdkB.jpg" alt="year 4 work station"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other thread of year 4 is around React Knowledgeable, a weekly sharing we organize initially in our React team, and now another public section in Singapore. Our thoughts have evolved multiple times around how specifically to run it, but the motivation has remained rather constant – to have a consistent, fun and friendly podium to share what we learn as a React developer. I was once asked to write a few bullet points for the value of its existence and our manager threw out an example that goes "by listening to talks at RK a developer can learn...", and I immediately noticed that &lt;em&gt;that&lt;/em&gt; needed to be changed. It is less about the listening part that makes an average developer (me) a slightly better one &lt;em&gt;but the sharing part&lt;/em&gt;. At this one year mark more and more of us are starting to realize this, and our podium has become more stablized. We've grown from ~30 to ~40 developers, but that's still a very small group for our 43 weeks of 60+ talks. Two thirds of us have spoken and nearly all spoke multiple times. I find that pretty amazing even today. Some of the talks we have are &lt;em&gt;way&lt;/em&gt; beyond expectations for an internal sharing, trully the most brilliant team I've ever had the fortune to be in and I'm really very overly proud of this.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://reactknowledgeable.org/"&gt;Singapore chapter of React Knowledgeable&lt;/a&gt; is just getting started. I don't know where I obtained the luck to have onboarded a few of the coolest React developers I've ever met. And so RK is shaped up by more cool minds now, calling for attention and caring from a bigger audience, as well as available to more people for grab. The meetup version is different from an internal sharing, and we haven't completely figured out where it rounds. But I think the learning spirits and the fun and friendly podium should stay.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--02p2jV8W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/mavWT98.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--02p2jV8W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/mavWT98.jpg" alt="more involvement with the local tech scene means many more stickers"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I've had troubles ending this article because I still have a tonne of questions I constantly wonder about. Eventually, I decided that instead of tossing out more of my crude thoughts, I'll refer to senpai's thoughts. My favorite deskmate &lt;a href="https://twitter.com/kenrick95/"&gt;Kenrick&lt;/a&gt; has on his pinned tweet this article &lt;a href="https://peternixey.com/post/83510597580/how-to-be-a-great-software-developer"&gt;How to be a Great Software Developer&lt;/a&gt; that I think is worth a read.&lt;/p&gt;

&lt;p&gt;Most people finish college in four years. In retro, the biggest challenge for myself as a developer is that I'm not great at engineering, or say the implementation side of things. My brain calls it a mission complete at understanding the intuitive meaning and I'm still fairly scared at getting my hands dirty. &amp;lt;!-- But I now think natural talent is misleading direction to look at because it overlooks how people make contributions and define their own unique values they create, both of which are more subjective than about being "natural". --&amp;gt; On the other hand, I think I'm overly well treated by this career and community, and people around me, so I have no excuses. And therefore I'll find ways to get better at implementation and get hands dirty &lt;code&gt;¯\_(ツ)_/¯&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So yeah, these are my first four years as front end. First thing other than math I've broken my two-year limit in consistent effort. Hopefully I'm a graduate now. By no means saying I'll stop learning or whatever, instead looking forward to the many more four years challenges ahead.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Outerspace Operation</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Sat, 12 Oct 2019 11:17:31 +0000</pubDate>
      <link>https://forem.com/wgao19/outerspace-operation-2fgl</link>
      <guid>https://forem.com/wgao19/outerspace-operation-2fgl</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Recently I'm working on a project generator. I think a blueprint to create a planet is a good analogy. The blueprint is how we want users to build this certain type of planet. And inside this blueprint, there are some core features which we want to share, some for consistency, some others for future exploration. So we extract them out and put them in a "headquarter". The headquarter then exports a few app layer things such that the planets created will look alike. It also provides some APIs to satisfy feature and customizability needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;I've been bugged by the thoughts around some "very procedural API". What I mean by &lt;em&gt;very procedural API&lt;/em&gt; is something that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;someOuterSpaceOperation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;headquarter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyPlanet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;someOuterSpaceOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi headquarter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    called from my planet
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Namely, we don't want the API to look like anything related with the component's life cycle. So no hooks, better no syntax sugars like &lt;code&gt;connect&lt;/code&gt; neither. I'm free to hide the logic somewhere, maybe by the boundary of a file import, after which the user of the API may spell the magic code &lt;code&gt;someOuterSpaceOperation()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The but the action is not &lt;em&gt;that&lt;/em&gt; outer space. In connects back to certain component inside &lt;code&gt;headquarter&lt;/code&gt;, and &lt;code&gt;someOuterSpaceOperation&lt;/code&gt; may result in a component update. And in the remainder of the universe, we want creatures on those planets to be able to call &lt;code&gt;someOuterSpaceOperation()&lt;/code&gt; without realizing we'll still on the nether of a same React app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Honestly, I was very, very stuck with this because I felt my imagination was very limited by the React APIs and the existing libraries. I had some rough thoughts around creating and maintaining some kind of store on our own, maybe write some flexible JavaScript to subscribe to it. But I was unable to see how that should actually happen, or where exactly relevant code should go, until &lt;a href="https://jiongks.name"&gt;Jinjiang&lt;/a&gt; sent me an example demo, which I then developed to &lt;a href="https://codesandbox.io/s/outerspace-operation-1f1m0"&gt;this codesandbox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Rough idea: Create a store and have &lt;code&gt;headquarter&lt;/code&gt; subscribe to it. The setter side of the store, however, we export to the planets to consume directly.&lt;/p&gt;

&lt;p&gt;So my tiny store will look like this. It maintains a store value, a setter and a getter function, and a way to subscribe to it. It has a couple of assumptions: the store value must be an object, and it allows only one listener. Both assumptions are satisfied in the use case with our &lt;code&gt;headquarter&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Store&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;initValue&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initValue&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
  &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;newValue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;subscribe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cb&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;cb&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cb&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Store&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With this &lt;code&gt;Store&lt;/code&gt; class, we can create a store and export the very procedural API we desired, it is free to be called outside of a component's lifecycle,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Store&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./store&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;outerspaceHQStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// setAgent can be called outside of a component's lifecycle&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setAgent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;outerspaceHQStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;agent&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now in our headquarter, subscribe to the store and put that store value in a stateful variable, then inside a context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AgentProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// manage subscription here&lt;/span&gt;
  &lt;span class="c1"&gt;// put in react component tree an internally maintained stateful variable&lt;/span&gt;
  &lt;span class="c1"&gt;// that is subscribed to the newest val&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setVal&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;outerspaceHQStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="nx"&gt;outerspaceHQStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setVal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AgentContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AgentContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here I used something I learned from &lt;a href="https://github.com/jamiebuilds/unstated-next"&gt;Jamie's hook-based Unstated library&lt;/a&gt;, wrapping and re-exporting the context provider allows us to keep all the logic about this API in one place.&lt;/p&gt;

&lt;p&gt;Then, the users of our very procedural API is able to call &lt;code&gt;setAgent&lt;/code&gt; anywhere they want, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ComponentThatSetsAgent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
    &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;setAgent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    call outerspace!
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then inside &lt;code&gt;headquarter&lt;/code&gt;, we're able to grab the variable subscribed to our store from its corresponding context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ComponentThatDisplaysAgent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// grabs the value from context&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;agent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AgentContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;received call from agent &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;agent&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Other thoughts
&lt;/h2&gt;

&lt;p&gt;First time I do silly things with React, feels a bit hacky, and very unsure. Turns out, I'm home cooking state management with a connector, with a very naive subscription? Also, the contrast is stiff. I mean, I previously thought it was out of my imagination but it seems pretty obvious to me now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Relevant links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/outerspace-operation-1f1m0"&gt;demo codesandbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jamiebuilds/unstated-next"&gt;Jamie's hook-based Unstated library&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Annotating Connected Components with Flow</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Mon, 01 Jul 2019 06:11:08 +0000</pubDate>
      <link>https://forem.com/wgao19/annotating-connected-components-with-flow-1nn1</link>
      <guid>https://forem.com/wgao19/annotating-connected-components-with-flow-1nn1</guid>
      <description>&lt;p&gt;After Flow 0.85, Flow starts &lt;a href="https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8" rel="noopener noreferrer"&gt;Asking for Required Annotations&lt;/a&gt; on implicit calls of higher order components within each file import — export cycle. This facilitates Flow to merge type information from file dependencies &lt;em&gt;before&lt;/em&gt; it walks the type structure and conducts type inference.&lt;/p&gt;

&lt;p&gt;This helps Flow gain significantly better coverage on higher order components. But it also asks that we explicitly annotate the connected components at file exports. Exporting implicit calls of &lt;code&gt;connect&lt;/code&gt; will raise error:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Missing type annotation for OP. OP is a type parameter declared in function type [1] and was implicitly
instantiated at call of connect [2].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In general, to make Flow happy with connect after 0.85 is a two-phase fix. First, you need to explicitly annotate each connected components at file exports. This shall clear all the “implicitly instantiated” errors. Then, if your codebase contains mismatched types between component definitions and usages, Flow will report those errors after you fix the implicit instantiation errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing the “implicitly instantiated” errors at calls of &lt;code&gt;connect&lt;/code&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We need &lt;code&gt;React.AbstractComponent&lt;/code&gt; from Flow v0.89+&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Annotating at function return
&lt;/h3&gt;

&lt;p&gt;The easiest way to annotate connected components is to annotate at function call return. To do this, we need to know to types of props in our components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;OwnProps&lt;/code&gt;: likely contain or equal to what you need as the second parameter to &lt;code&gt;mapStateToProps&lt;/code&gt;. If there are props that are not used by &lt;code&gt;mapStateToProps&lt;/code&gt;, i.e., the props that "pass through", include them here in &lt;code&gt;OwnProps&lt;/code&gt; as well&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Props&lt;/code&gt;: &lt;code&gt;OwnProps&lt;/code&gt; plus the props passed in by &lt;code&gt;mapStateToProps&lt;/code&gt; and &lt;code&gt;mapDispatchToProps&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Inexact objects don't spread nor &lt;code&gt;$Diff&lt;/code&gt; very well. It is strongly recommended that you use exact objects for connected components all the time.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;forMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;OwnProps&lt;/code&gt; and &lt;code&gt;Props&lt;/code&gt; in figured out, we are now ready to annotate the connected components.&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;component definition&lt;/em&gt;, annotate the props with &lt;code&gt;Props&lt;/code&gt;. The component will have access to all the injected props from &lt;code&gt;connect&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dispatch1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passthrough&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we export, this is also when we normally call &lt;code&gt;connect&lt;/code&gt;, annotate the exported component with &lt;em&gt;just&lt;/em&gt; &lt;code&gt;OwnProps&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// const MyComponent = ...&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;
&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AbstractComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Annotating by providing explicit type parameters
&lt;/h3&gt;

&lt;p&gt;We may also annotate connected components by providing explicit type parameters at call of &lt;code&gt;connect&lt;/code&gt; with the help of the &lt;a href="https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/react-redux_v5.x.x/flow_v0.89.x-/react-redux_v5.x.x.js" rel="noopener noreferrer"&gt;newest Flow Typed library definition for React Redux&lt;/a&gt;. Note that this will also require Flow v0.89+.&lt;/p&gt;

&lt;p&gt;The Flow Typed library definition declares &lt;code&gt;connect&lt;/code&gt; as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;OP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;SP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;DP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mergeProps&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="nx"&gt;Options&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;MergeOP&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;OP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Connector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MergeOP&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;OP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The libdef also contains a &lt;a href="https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/react-redux_v5.x.x/flow_v0.89.x-/react-redux_v5.x.x.js#L14" rel="noopener noreferrer"&gt;glossary of the abbreviations&lt;/a&gt; which decrypts the signature to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;StateProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;DispatchProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Dispatch&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the most common ways to connect components, we won't need all of the parameters. Normally, we need only &lt;code&gt;OwnProps&lt;/code&gt; and &lt;code&gt;Props&lt;/code&gt; at the call of &lt;code&gt;connect&lt;/code&gt;, and &lt;code&gt;State&lt;/code&gt; at the definition of &lt;code&gt;mapStateToProps&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We may use &lt;code&gt;_&lt;/code&gt; (&lt;a href="https://github.com/facebook/flow/commit/ec70da4510d3a092fa933081c083bd0e513d0518" rel="noopener noreferrer"&gt;what's this?&lt;/a&gt;) as placeholder at unused type parameter positions. A common &lt;code&gt;connect&lt;/code&gt; call may look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We include examples for three major use cases of annotating &lt;code&gt;connect&lt;/code&gt; with Flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connecting stateless component with &lt;code&gt;mapStateToProps&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Connecting components with &lt;code&gt;mapDispatchToProps&lt;/code&gt; of action creators&lt;/li&gt;
&lt;li&gt;Connecting components with &lt;code&gt;mapStateToProps&lt;/code&gt; and &lt;code&gt;mapDispatchToProps&lt;/code&gt; of action creators&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Connecting stateless component with &lt;code&gt;mapStateToProps&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;forMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fromStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Com&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passthrough&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromStateToProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fromStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;str&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Connected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;Com&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Connecting components with &lt;code&gt;mapDispatchToProps&lt;/code&gt; of action creators
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Com&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passthrough&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Connected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;Com&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Connected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Connected&lt;/span&gt; &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Connecting components with &lt;code&gt;mapStateToProps&lt;/code&gt; and &lt;code&gt;mapDispatchToProps&lt;/code&gt; of action creators
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;forMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Com&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passthrough&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MapStateToPropsProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;forMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MapStateToPropsProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Connected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;Com&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Annotating nested higher order components with connect
&lt;/h3&gt;

&lt;p&gt;If you are at the unfortunate position where your component is wrapped with nested higher order component, it is probably more difficult to annotate by providing explicit type parameters, as doing so will probably require that you tediously take away props at each layer. It is agian easier to annotate at function return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="na"&gt;passthrough&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;forMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;injectedA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;injectedB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// annotate the component with all props including injected props&lt;/span&gt;
  &lt;span class="cm"&gt;/** ... */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ownProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fromMapStateToProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;str&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ownProps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forMapStateToProps&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;dispatch1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;dispatch2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;withA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;withB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AbstractComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;OwnProps&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// export the connected component without injected props&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Benefits of this version
&lt;/h2&gt;

&lt;p&gt;After fixing the implicit instantiation errors, if your code contains mismatched types between connected components, the total number of errors may go &lt;em&gt;up&lt;/em&gt;. This is the result of Flow's improved coverage. If you are using console output for the Flow errors, you may not be able to see those errors until you clear other errors. These additional errors are grouped together, all tied back to React Redux's library definition, and have friendly error messages that will pin point you to the lines of code to the errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fmt79yaC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fmt79yaC.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8" rel="noopener noreferrer"&gt;Asking for Required Annotations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Upgrading guides&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/jbrown215/f425203ef30fdc8a28c213b90ba7a794" rel="noopener noreferrer"&gt;Ville's and Jordan Brown's guide: &lt;em&gt;Adding Type Parameters to Connect&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/wgao19/quick-note-fixing-connect-flowtype-annotation-after-089-joi"&gt;Quick Note Fixing &lt;code&gt;connect&lt;/code&gt; FlowType Annotation after 0.89&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Talks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://engineers.sg/video/flow-be-happy-reactjs-singapore--3419" rel="noopener noreferrer"&gt;Flow Be Happy&lt;/a&gt; A talk on upgrading Flow past 0.85, &lt;a href="https://flow-be-happy.netlify.com/" rel="noopener noreferrer"&gt;slides&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Others&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/wgao19/flow-notes" rel="noopener noreferrer"&gt;Flow Notes&lt;/a&gt; A repo where I herd my notes on Flow&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/react-redux_v5.x.x/flow_v0.89.x-/test_connect.js" rel="noopener noreferrer"&gt;Flow Typed tests for React Redux &lt;code&gt;connect&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/flow-typed/flow-typed/issues/2946" rel="noopener noreferrer"&gt;flow-typed/#2946: Discussion after 0.85&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Add support for Flow 0.89+: &lt;a href="https://github.com/flow-typed/flow-typed/pull/3035" rel="noopener noreferrer"&gt;#3012&lt;/a&gt;, &lt;a href="https://github.com/flow-typed/flow-typed/pull/3035" rel="noopener noreferrer"&gt;#3035&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/ec70da4510d3a092fa933081c083bd0e513d0518" rel="noopener noreferrer"&gt;What's &lt;code&gt;_&lt;/code&gt;?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>flow</category>
      <category>flowtype</category>
    </item>
    <item>
      <title>Notes on Flow 0.100</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Tue, 25 Jun 2019 10:32:15 +0000</pubDate>
      <link>https://forem.com/wgao19/notes-on-flow-0-100-5c6k</link>
      <guid>https://forem.com/wgao19/notes-on-flow-0-100-5c6k</guid>
      <description>&lt;p&gt;Flow &lt;a href="https://github.com/facebook/flow/releases/tag/v0.100.0"&gt;0.100&lt;/a&gt; is out 💯. Reading and learning about Flow and JavaScript as always. This time, I have a short note on object destructuring, React type definitions, and put a link to a nice article explaining variance sigils.&lt;/p&gt;

&lt;p&gt;Flow 0.100 has very nice release notes with examples. So I won't repeat what is already said there. Here are some bullet points I jotted down as I tried to learn about the changes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Destructuring objects in function parameters
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Destructuring patterns could previously include missing properties if the resulting binding was unused. This is now an error even when unused. &lt;a href="https://flow.org/try/#0C4TwDgpgBA8lC8UDeUwC4oGdgCcCWAdgOZQC+A3AFAD01UAojjgPY4YAqAFhDtHplALNULSDlBQABgEdJUQlFCQpMSQBooAQwHMAZlABiAG2YB3KADcADADoAjFdtXKugK4EAxsDzMCUXQAUSGAa0qQYMACUyKRAA"&gt;Try Flow example&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;O&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Error: There is no property `q` in type `O`, as of Flow v0.100.0&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;q&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;O&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One confusion I encountered was this&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Does it mean all object will be exact?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I took this chance to clarify some of the things around here. Exact means the object passed in here &lt;em&gt;must not&lt;/em&gt; contain extra fields (&lt;a href="https://flow.org/en/docs/types/objects/#toc-exact-object-types"&gt;link to doc&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Sealed, on the other hand, means the object may contain other fields but you may not access them unless you annotate them. When we write an object type with some fields, it is by default &lt;em&gt;sealed&lt;/em&gt;. Trying to access unannotated field of a sealed object will result in error, regardless of it being exact or not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Sealed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sealed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;sealed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// error&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sealed&lt;/span&gt; &lt;span class="c1"&gt;// error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For functions that expect sealed objects, you can still pass in objects with extra props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;usingSealed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Sealed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// does things&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;usingSealed&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// ok&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Not so when the functions are expecting &lt;em&gt;exact&lt;/em&gt; objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Exact&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;usingExact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Exact&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// does things&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;usingExact&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We may access the fields of function parameters by destructuring the object:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// destructuring on function parameter&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;goodUsingSealed&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;Sealed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// ok&lt;/span&gt;
  &lt;span class="c1"&gt;// does things&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But since destructuring means accessing the object, we &lt;em&gt;should not&lt;/em&gt; be able to access extra props to sealed objects. This is fixed in 0.100:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// fixed in 0.100&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;badUsingSealed&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;Sealed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// error after 0.100&lt;/span&gt;
  &lt;span class="c1"&gt;// does things&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  React component types
&lt;/h2&gt;

&lt;p&gt;There are a bunch of changes around React library definitions. And so it's a good chance to take a step back and look at what they are in all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/facebook/flow/blob/master/lib/react.js"&gt;Here&lt;/a&gt; is the link to the React library definitions by Flow.&lt;/p&gt;

&lt;p&gt;My list of commonly used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;React$Component&amp;lt;Props, State = void&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;AbstractComponent&amp;lt;-Config, +Instance = mixed&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;React$ComponentType&amp;lt;-Config&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;React$ElementType&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;React$Element&amp;lt;+ElementType: React$ElementType&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;(new) &lt;code&gt;React$MixedElement = React$Element&amp;lt;React$ElementType&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;(new) &lt;code&gt;MixedElement = React$MixedElement&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;React$Ref&amp;lt;ElementType: React$ElementType&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the definitions above, those with the angled brackets are polymorphic types. This means you'll need to supply type parameters for those polymorphics.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;React$Component&amp;lt;Props, State = void&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;React$Component&lt;/code&gt; is the base class of ES6 React classes, modeled as a polymorphic class whose main type parameters are Props and State.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;React$AbstractComponent&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;React$AbstractComponent&lt;/code&gt; is the type name used by Flow, and is used by a few different types of React classes and components in React's library declarations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React.AbstractComponent&lt;/code&gt; uses it directly, which takes two parameters, &lt;code&gt;Config&lt;/code&gt; for the props type, and &lt;code&gt;Instance&lt;/code&gt; for an instance. Functional components have &lt;code&gt;Instance: void&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;React$ComponentType&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;React$ComponentType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React$AbstractComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mixed&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Aliased to &lt;code&gt;React$AbstractComponent&amp;lt;Config, mixed&amp;gt;&lt;/code&gt;, and is used as the type of a component in React. It can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stateless functional components. Functions that take in props as an argument and return a React node.&lt;/li&gt;
&lt;li&gt;ES6 class component. Components with state defined either using the ES6 class syntax, or with the legacy &lt;code&gt;React.createClass()&lt;/code&gt; helper.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;React$ElementType&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;React$ElementType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;React$AbstractComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mixed&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The type of an element in React. A React element may be a:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;string&lt;/code&gt;: These elements are intrinsics that depend on the React renderer implementation.&lt;/li&gt;
&lt;li&gt;React component. See &lt;code&gt;ComponentType&lt;/code&gt; for more information about its different variants.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few more related with &lt;code&gt;ElementType&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;React$Element&lt;/code&gt; is the type of a React element. React elements are commonly created using JSX literals, which desugar to React.createElement calls (see below).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;React$Element&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;+&lt;/span&gt;&lt;span class="nx"&gt;ElementType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React$ElementType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ElementType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React$ElementProps&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ElementType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React$Key&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, here are the two new types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;React$MixedElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React$Element&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React$ElementType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;declare&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MixedElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React$MixedElement&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A keen reader may have noticed that above is more or less a copy and paste of comments and code snippets from Flow's codebase. They are really very well-written and a significant portion of the code itself is self-explanatory.&lt;/p&gt;




&lt;h2&gt;
  
  
  Variance sigils
&lt;/h2&gt;

&lt;p&gt;Variance sigils are everywhere in library definitions. If this set of synonyms works for you, feel free to think of covariance as read-only, and contravariance as write-only.&lt;/p&gt;

&lt;p&gt;This article &lt;a href="https://medium.com/@forbeslindesay/covariance-and-contravariance-c3b43d805611"&gt;Flow's Best Kept Secret&lt;/a&gt; explains it very well.&lt;/p&gt;

&lt;h2&gt;
  
  
  🐶 Till next time
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/facebook/flow/releases/tag/v0.101.0"&gt;Flow 0.101&lt;/a&gt; is already out and I'm falling behind 😭 It's &lt;a href="https://2019.jsconf.asia/"&gt;JSConf.Asia&lt;/a&gt; at home now. Gonna chill down a bit next week and get back to my normal Flow :]&lt;/p&gt;

</description>
      <category>flowtype</category>
    </item>
    <item>
      <title>Flow 0.99: Callable Properties, Function Statics, and More</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Sat, 01 Jun 2019 22:15:18 +0000</pubDate>
      <link>https://forem.com/wgao19/flow-0-99-callable-properties-function-statics-and-more-5c82</link>
      <guid>https://forem.com/wgao19/flow-0-99-callable-properties-function-statics-and-more-5c82</guid>
      <description>&lt;p&gt;&lt;a href="https://unsplash.com/photos/PwQHfxo3Q2Y"&gt;Cover image: Text of Time #9&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flow &lt;a href="https://github.com/facebook/flow/releases/tag/v0.99.0"&gt;released 0.99&lt;/a&gt; (&lt;a href="https://github.com/facebook/flow/compare/v0.98.0...v0.99.0"&gt;comparing changes&lt;/a&gt;) a few days ago. This release contains changes around callable properties, function statics, a few more utilities coming from the React Component realm, bugfixes, and performance improvements for Flow server.&lt;/p&gt;

&lt;p&gt;Once again I'm using those bits and bites to understand more about Flow and JavaScript, and this time it'll be mostly around callable properties and function statics, which I'll share about in this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  🍾 Function statics
&lt;/h2&gt;

&lt;p&gt;Here is one change that caused new errors in our codebase:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/facebook/flow/commit/b868f61026b9b34cb22c3f59e1bcbb65a614c71b"&gt;Make function type statics stricter&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before this change, we optimistically typed the statics of a function type as &lt;code&gt;any&lt;/code&gt;, under the assumption that a function would not be used as an object. In practice, our optimism here is unfounded.&lt;/p&gt;

&lt;p&gt;This diff changes the type of the statics object for function types to an empty, inexact object type with Function.prototype for its &lt;strong&gt;proto&lt;/strong&gt;. This choice is sound with respect to the runtime behaviors while also allowing functions with statics to be valid subtypes via width subtyping.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Time for a review on JavaScript. What are &lt;em&gt;function statics&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;For a JavaScript &lt;em&gt;class&lt;/em&gt;, a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Static_methods"&gt;&lt;em&gt;static method&lt;/em&gt;&lt;/a&gt; is a method for the class, not instances of that class.&lt;/p&gt;

&lt;p&gt;For a JavaScript &lt;em&gt;function&lt;/em&gt;, &lt;em&gt;statics&lt;/em&gt; refer to those weird moments where you may have a variable that can be accessed by saying function name dot that variable name because functions are also objects in JavaScript 🤷🏻‍♀️. Consider this greeting function with a counter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So what this change says is that previously Flow did not put any restrictions on function statics, i.e., they were typed to &lt;code&gt;any&lt;/code&gt;. In the example above, this would mean that &lt;code&gt;greeting.counter&lt;/code&gt; is a field of &lt;code&gt;any&lt;/code&gt;, and is therefore unrestricted.&lt;/p&gt;

&lt;p&gt;You may type function statics, for example:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Play around in the &lt;a href="https://flow.org/try/#0PTAEAEDMBsHsHcBQjIFcB2BjALgS1uqAOYBOApmXukQBToCGAtmQJSgDeiooNpFVRAHSZYGbGRIAuUOlSMARhJZdQuSDwCEfSrmrDR6cSTadu3bQP1iJoALygADAG4VAXxUXdQkdZIBqPxducmxUEkIAcgALMmg4ABpQCNA-GSYyF1cgA"&gt;Try Flow&lt;/a&gt; and note that if you change the annotation of &lt;code&gt;counter&lt;/code&gt; to &lt;code&gt;string&lt;/code&gt;, Flow is catching the error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;4:   &lt;span class="o"&gt;(&lt;/span&gt;greeting.counter: string&lt;span class="o"&gt;)&lt;/span&gt;
      ^ Cannot cast &lt;span class="sb"&gt;`&lt;/span&gt;greeting.counter&lt;span class="sb"&gt;`&lt;/span&gt; to string because number &lt;span class="o"&gt;[&lt;/span&gt;1] is incompatible with string &lt;span class="o"&gt;[&lt;/span&gt;2].
References:
6:     greeting.counter &lt;span class="o"&gt;=&lt;/span&gt; 0&lt;span class="p"&gt;;&lt;/span&gt;
                          ^ &lt;span class="o"&gt;[&lt;/span&gt;1]
4:   &lt;span class="o"&gt;(&lt;/span&gt;greeting.counter: string&lt;span class="o"&gt;)&lt;/span&gt;
                        ^ &lt;span class="o"&gt;[&lt;/span&gt;2]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  🐿 New error in our codebase
&lt;/h3&gt;

&lt;p&gt;The real error that happened in our codebase, however, is a bit different.&lt;/p&gt;

&lt;p&gt;We write our Redux actions with data wrapped around in a field conventionally referred to as &lt;em&gt;payload&lt;/em&gt;. And we normally annotate payload like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ActionPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Sometimes &lt;code&gt;payload&lt;/code&gt; can be a function that returns an object containing the data, so we're happy to see this too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FETCH_DATA&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;ActionPayload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// function body&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In a few occasions, though, we mistyped the payload in the function form, where the payload is actually just the object. So our code worked fine and no one noticed that the annotation isn't making sense at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FETCH_DATA&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;ActionPayload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;- wrooooong, or not?&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At 0.99, as function statics are now typed to &lt;code&gt;{}&lt;/code&gt;, Flow is complaining that we cannot get &lt;code&gt;data&lt;/code&gt; because &lt;code&gt;data&lt;/code&gt; is missing in &lt;em&gt;statics of function type&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A similar scenario is a mixture of actions and action creators. They get passed around quite often, which makes typing even hairier. I realize that Flow really is getting in our way when we try to be smart in this direction. I like the flexibility but the complaints will keep asking me whether this is a good pattern or not, which I do not yet have an answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  👾 Callable property syntax
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/facebook/flow/commit/cbd64384dccaddaa8461d7850c24419e2217d13e"&gt;Remove deprecated &lt;code&gt;$call&lt;/code&gt; property syntax&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First of all, to not be confused, this is &lt;em&gt;not&lt;/em&gt; &lt;a href="https://flow.org/en/docs/types/utilities/#toc-call"&gt;the &lt;code&gt;$call&lt;/code&gt; utility type&lt;/a&gt;, which helps you get the return type of a given function, and is not deprecated nor removed.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/facebook/flow/commit/df8ee96bc84b476f874e300b3cd3c07b430e085b"&gt;deprecated &lt;code&gt;$call&lt;/code&gt; property syntax&lt;/a&gt; was the precursor of this &lt;a href="https://github.com/facebook/flow/commit/b9db648afe4f2207a49985aa82b90a485a11a900"&gt;callable syntax&lt;/a&gt;, both the addition of the new syntax and the deprecation of the old happened in &lt;a href="https://github.com/facebook/flow/releases/tag/v0.75.0"&gt;0.75&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So what are they about, anyway?&lt;/p&gt;

&lt;p&gt;It ties back to the fact we mentioned earlier that with JavaScript functions are also objects. And here's an interesting insight from Flow:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An object with a callable property can be equivalently viewed as a function with static fields.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And so it turns out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// You should be able to call objects with call properties&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;g&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ...and get an error if the return type is wrong&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And similarly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// You should be able to use an object as a function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Most amazing #TIL for me is perhaps this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Multiple call properties should also be supported&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// It should be fine when a function satisfies them all&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And here is another one that reminds us about functions, that those monadic chained calls made possible by prototypes come down to not much more than a field in a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Expecting properties that do exist should be fine&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So that's a really interesting feature that Flow possesses! That means you can annotate memoized functions with Flow and I never even thought of that before learning all this. Consider a &lt;em&gt;memoized factorial&lt;/em&gt; (&lt;a href="https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AWSwLawCWAXlgCYBiAhgMYqwBOxN0AKpjgLygDeiUKDr0AFlgBc-QaACQAbQB2AVwIAjLEwC6Ules0yAvgBoZ8+SOjQtWgBR6NTAJS7Vj04eR1YigM4pQSHpGFjYpfCIySloGZlYOLlBeRSSAPmkhYkhQWwBCINjQ6AA6ETpxJwyhQOC4tlKxHn5PIRbQLJyCkPiG8qwlLVBc7l5lRQosSGJFSkqBatAmLBRlJhSuupKy8QGjGQ2i3p3FQeSkkdAABlAAflAARlBdUAAqGsL4+1AAWgenGSWKzW7269W2-ROiEMQA"&gt;Try Flow&lt;/a&gt;) and you can annotate it expressively with Flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MemoizedFactorialType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;]](&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MemoizedFactorialType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;There are a few more changes around callable properties in this version, which I'll list out their references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/5d7e01d06b85388882b3214e383d26b73e6de111"&gt;Fix implicit proto for objects with &lt;code&gt;[[call]]&lt;/code&gt; properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/b9e26fd3bf7ba10e8f2f8c4e9c90d7f92afe96e1"&gt;Model multiple call properties as an intersection of callable objects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/0938da8d7293d0077fbe95c3a3e0eebadb57b012"&gt;Concretize callable object params before intersection processing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/3c5a41026f8da473b3869e0ef6d84afa0b978816"&gt;Remove &lt;code&gt;[[call]]&lt;/code&gt; property from function statics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here is a couple more links to some older commits you may want to look at regarding callable properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/b9db648afe4f2207a49985aa82b90a485a11a900"&gt;Store object call properties in internal slot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/954a72704a6338778c940239573045b28c716488"&gt;Add support for &lt;code&gt;[[call]]&lt;/code&gt; internal slot properties&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🦖 Other notable changes
&lt;/h2&gt;

&lt;p&gt;There are few more notable changes I'll just list here for now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/65e6d1df078e778d0244d4ee49bd28c741b5af0f"&gt;Allow function types inside tuples inside arrow return types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/2ac4372e31a1f3a03ae963ed7a89b2118b862aad"&gt;&lt;code&gt;React$Config&lt;/code&gt;, &lt;code&gt;React$ElementRef&lt;/code&gt;, &lt;code&gt;React$ElementConfig&lt;/code&gt; and &lt;code&gt;React$ElementProps&lt;/code&gt; are now utility types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/6dd62e0d9e0dd3e65a07310abc67a022e6335e1f"&gt;&lt;code&gt;Fragment&lt;/code&gt;'s children are now correctly optional&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/72462e4f5849f3e5fe27b15bde54aede8b27b8b8"&gt;Existential type &lt;code&gt;*&lt;/code&gt; is deprecated&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you find any of those interesting and have learned something about them, please please write about them because ever since 0.85 my learning about Flow has felt like sitting in a class where no one asks any questions but apparently not many people understand what's going on 🤦🏻‍♀️. Secretly I'm also not completely certain about things I said about Flow. If you spot any mistakes, please do &lt;a href="https://twitter.com/wgao19/"&gt;let me know&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  💯 Till next time
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/facebook/flow/releases/tag/v0.100.0"&gt;Flow 0.100&lt;/a&gt; is released too. If you haven't noticed, the release notes now come with Try Flow examples. Maybe the added digit indicates a new era.&lt;/p&gt;

</description>
      <category>flowtype</category>
      <category>flow</category>
    </item>
    <item>
      <title>Night Mode 🌚🌝 with Mix Blend Mode: Difference</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Sat, 04 May 2019 16:28:15 +0000</pubDate>
      <link>https://forem.com/wgao19/night-mode-with-mix-blend-mode-difference-23lm</link>
      <guid>https://forem.com/wgao19/night-mode-with-mix-blend-mode-difference-23lm</guid>
      <description>&lt;p&gt;I came across the idea of &lt;em&gt;implementing night mode using&lt;/em&gt; &lt;code&gt;mix-blend-mode: difference&lt;/code&gt; when I was preparing for my talk &lt;a href="https://speak.wgao19.cc/slides/1904-mixed-and-blended"&gt;This World Mixed and Blended&lt;/a&gt; (these slides require color font support, i.e., FireFox / Safari). The original idea was only meant for a showcase and &lt;a href="https://caniuse.com/#search=mix-blend-mode"&gt;the browser support is currently limited&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Still, I implemented it to my dev blog and had a lot of fun. So this will be what this post is about. Meanwhile, as I thought more about it, it occurs to me now that this &lt;em&gt;can be&lt;/em&gt; a legit preferred way night mode is to be done. And let me share a bit about the intuition behind that as well.&lt;/p&gt;

&lt;p&gt;Please note that this is not a standard way of implementing dark mode. To see how people normally do it, you may want to see &lt;a href="https://github.com/gaearon/overreacted.io/blob/master/src/html.js#L47"&gt;here&lt;/a&gt; for how Dan Abramov does it for Overreacted, or &lt;a href="https://dev.to/ananyaneogi/create-a-dark-light-mode-switch-with-css-variables-34l8"&gt;this post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz3pujr1curwk9zo5007.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz3pujr1curwk9zo5007.gif" width="600" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding &lt;code&gt;mix-blend-mode: difference&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mix-blend-mode: difference&lt;/code&gt; is one of the blending modes CSS supports, as specified in &lt;a href="https://www.w3.org/TR/compositing-1/"&gt;Compositing and Blending Level 1&lt;/a&gt;. &lt;a href="https://www.w3.org/TR/compositing-1/#blending"&gt;Blending modes&lt;/a&gt;, in turn, specify how colors mix when graphics are stacked together. The graphics do not limit to images. Any rendered graphics, content of divs, texts, emojis 🌚🌝, svgs, may participate in the blending.&lt;/p&gt;

&lt;p&gt;I'd like to think of that as the process where browsers check with us whenever they are about to paint a new element: “Hey, it seems that this next pixel I'm painting is red, but currently I am seeing a blue on the ground, by any chance you want me to combine those colors together, and if so, how?”&lt;/p&gt;

&lt;p&gt;Blending modes allow us to create some very interesting effects such as overlaying texts on an image while revealing the texture of the graphics directly in a browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sailfi7z0g5eddackdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sailfi7z0g5eddackdg.png" width="510" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example of blending mode from &lt;a href="https://www.w3.org/TR/compositing-1/"&gt;Compositing and Blending Level 1&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Definition
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;mix-blend-mode: difference&lt;/code&gt;, in particular, is one of the blending modes that is defined as taking the absolute value of the difference between the two colors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;difference(A, B) = |A - B|
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an abstraction of the actual computation, where for each color we meant three numbers representing the R, G, and B channels, respectively. As an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;difference(
    rgb(255, 255, 255),
    rgb(0, 100, 200)
) = rgb(255, 155, 55)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile, taking the absolute value makes the operation &lt;em&gt;commutative&lt;/em&gt;, meaning &lt;code&gt;B(A, B) = B(B, A)&lt;/code&gt;. In another words, it doesn't matter which graphic is laid on top of the other, the result is going to be the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intuition
&lt;/h3&gt;

&lt;p&gt;What exactly is the blending mode &lt;em&gt;difference&lt;/em&gt; doing? The definition seems straightforward. However, our minds may not be very good at perceiving what will happen to the resultant color before actually seeing them. To name an example, &lt;em&gt;difference(white, red)&lt;/em&gt; is essentially deducing the complement color of red, which is teal. But how can you “see” it until you actually &lt;em&gt;saw&lt;/em&gt; it?&lt;/p&gt;

&lt;p&gt;The following pen is created by blending intersecting stripes of whites and reds only.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wgao19/embed/GaKXZr?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Perhaps exactly because its hardly perceivable effects, we can use &lt;code&gt;mix-blend-mode: difference&lt;/code&gt; to create some contrasting visuals to spark surprises in UI, like this one by &lt;a href="https://codepen.io/maddesigns/"&gt;Sven Wolfermann&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/maddesigns/embed/dpGVGw?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This was the design that inspired me to think about creating dark mode using &lt;em&gt;difference&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing dark mode using &lt;code&gt;mix-blend-mode: difference&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;The idea is simple: When night mode is turned on, cover your site with a full-screen div with &lt;code&gt;background: white&lt;/code&gt; and &lt;code&gt;mix-blend-mode: difference&lt;/code&gt;, and save yourself the trouble of defining all the colors again 😉&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.dark-mode-screen&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;mix-blend-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why, though?&lt;/p&gt;

&lt;p&gt;The thought process involves two of the mathematicians' favorite numbers, 0 and 1.&lt;/p&gt;

&lt;p&gt;In unit space, 0 means &lt;em&gt;nothing&lt;/em&gt; and 1 means &lt;em&gt;everything&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In RGB colors, 0 means black and 1 (100% or 255) means white.&lt;/p&gt;

&lt;p&gt;Now let's think about our blog site, and let's assume that currently we have a white background and a black foreground. If we take the difference of that page against white, what do we get?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;background: currently white, the difference between white and white is &lt;em&gt;nothing&lt;/em&gt;, which means &lt;em&gt;black&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;foreground: currently black, which means &lt;em&gt;nothing&lt;/em&gt;, the difference between white and nothing is &lt;em&gt;white&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we have a &lt;em&gt;black background&lt;/em&gt; and a &lt;em&gt;white foreground&lt;/em&gt;, and look what is that? A reversed (dark) theme :)&lt;/p&gt;

&lt;p&gt;Furthermore, when taking the &lt;em&gt;difference&lt;/em&gt; of the page with &lt;em&gt;white&lt;/em&gt;, the contrast between the original background and foreground is automatically preserved. This does not only apply to blacks and whites. In fact, my code block with original theme &lt;em&gt;Dracula&lt;/em&gt; picks up a nice sepia-styled hue when inverted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxg28r8n1bchn2otgnyd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxg28r8n1bchn2otgnyd.png" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb0zvcgufqyfq1ki1x3qj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb0zvcgufqyfq1ki1x3qj.png" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Transition
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Scaling a div&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I put a toggle fixed to the lower bottom of the page. When the night mode is toggled on, I transform that toggle to scale up that covers the whole page. This effect is kind of showing off the original UX design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz3pujr1curwk9zo5007.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz3pujr1curwk9zo5007.gif" width="600" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opacity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you prefer a more subtle toggle, maybe tweaking &lt;code&gt;opacity&lt;/code&gt; is a better choice and the blending mode will work just as nice. With an easing timing function on the transition, this is perhaps the transition UI shared by most websites and blogs implementing a night mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihg03qew5k5boa7ayevp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fihg03qew5k5boa7ayevp.gif" width="600" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Isolate the elements that are not intended to blend
&lt;/h3&gt;

&lt;p&gt;As mentioned earlier, &lt;code&gt;mix-blend-mode&lt;/code&gt; will apply on &lt;em&gt;any&lt;/em&gt; graphics. However, when implementing dark mode, some elements may not be intended to blend. Such examples include logos of specific colors, emojis, etc. To specify that, you can put &lt;code&gt;isolation: isolate&lt;/code&gt; (&lt;a href="https://www.w3.org/TR/compositing-1/#isolation"&gt;reference&lt;/a&gt;) on those elements. Note that this will create a stacking context on the element that is isolated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* twitter logo and emoji should not blend */&lt;/span&gt;
&lt;span class="nc"&gt;.twitter-logo&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.emoji&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;isolation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;isolate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* elements that create their a stacking context are automatically isolated */&lt;/span&gt;
&lt;span class="nc"&gt;.footer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pick a colored hue for your dark mode
&lt;/h3&gt;

&lt;p&gt;As mentioned earlier, taking the difference between the page against white is like taking the complement color directly. You may not have to limit that choice of color to white. In fact, you can pick any color to take the difference with. For an effect of a darker theme where your site was initially on a light background, you may consider any color that is relatively light:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xe79hhpp1b62qfrbj8o.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xe79hhpp1b62qfrbj8o.gif" width="600" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are some of the technical details I've encountered. If you're trying this and encounter issues here and there, please feel free to let me know and I'd be glad if I can help.&lt;/p&gt;

&lt;p&gt;To see this thing in code, check out this CodePen:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wgao19/embed/vMzOgQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;p&gt;(apart from being geeky 😅)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don't have full range of colors. It saves you the trouble of specifying more colors, but you'd lose control over the dark colors — they'd be deduced from your light colors. Yet this may not be a limit but rather a design choice.&lt;/li&gt;
&lt;li&gt;Browser support of &lt;code&gt;mix-blend-mode&lt;/code&gt; is still not optimal, &lt;a href="https://caniuse.com/#search=mix-blend-mode"&gt;you're stuck with non-IE, relatively newer versions of browsers&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Performance can be a concern as well for its by-pixel and by-channel computation. Don't do crazy animations with it (yet).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Till next time 🤞
&lt;/h2&gt;

&lt;p&gt;Blending modes were citizens from computer graphics. I remember first playing around with them in Photoshop years ago. Now that browsers are becoming more powerful and we are seeing complex graphical features native to browser rendering. This doesn't mean we should implement a full photoshop in browsers and nor should we limit our imaginations to just that. Browsers and web pages have their own contexts and goals, as well as a different set of limits. Maybe we should welcome them like new habitants and discover use cases native to this territory.&lt;/p&gt;

&lt;p&gt;Once again, the inspiration credits to &lt;a href="https://codepen.io/maddesigns/pen/dpGVGw"&gt;this CodePen&lt;/a&gt;, a cute animation that strikes an impression at first sight. You should &lt;em&gt;hover over it&lt;/em&gt; 🙈&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/maddesigns/embed/dpGVGw?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I hope this serves as a friendly discovery about blending modes, and I hope you had fun same as I do.&lt;/p&gt;

</description>
      <category>css</category>
    </item>
    <item>
      <title>Making Flow Happy after 0.98</title>
      <dc:creator>Wei Gao</dc:creator>
      <pubDate>Tue, 30 Apr 2019 13:10:58 +0000</pubDate>
      <link>https://forem.com/wgao19/making-flow-happy-after-0-98-32bb</link>
      <guid>https://forem.com/wgao19/making-flow-happy-after-0-98-32bb</guid>
      <description>&lt;p&gt;It's a Monday after Flow updated 😱  0.98 seems to contain many fixes. Happy to see Flow making more sense version by version. I'm also glad to be learning bits and bites about Flow on the go so I thought I'd share about that :)&lt;/p&gt;

&lt;p&gt;Release notes are &lt;a href="https://github.com/facebook/flow/releases/tag/v0.98.0"&gt;here&lt;/a&gt;, and following are my notes. Flow please be happy 🤞&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Turn the deprecated-utility lint on by default&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible errors: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deprecated utility. Using &lt;code&gt;$Subtype&lt;/code&gt; types is not recommended! (deprecated-utility)&lt;/li&gt;
&lt;li&gt;Deprecated utility. Using &lt;code&gt;$Supertype&lt;/code&gt; types is not recommended! (deprecated-utility)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;deprecated-utility&lt;/code&gt; is a lint rule that was added &lt;a href="https://github.com/facebook/flow/releases/tag/v0.89.0"&gt;in 0.89&lt;/a&gt;. So far &lt;code&gt;$Subtype&lt;/code&gt; and &lt;code&gt;$Supertype&lt;/code&gt; are deprecated. However, Flow only starts to complain from this version because &lt;code&gt;deprecated-utility&lt;/code&gt; is now turned on by default.&lt;/p&gt;

&lt;p&gt;You can turn it off by adding back the lint option in &lt;code&gt;.flowconfig&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .flowconfig
[lints]
deprecated-utility=off
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But it's actually not that hard to fix. &lt;/p&gt;

&lt;p&gt;So what were &lt;code&gt;$Subtype&lt;/code&gt; and &lt;code&gt;$Supertype&lt;/code&gt; anyway? &lt;code&gt;$Subtype&lt;/code&gt; normally means what is expected here is more refined than what's inside &lt;code&gt;$Subtype&lt;/code&gt;. Anyway, that's just my understanding. You can still find the docs &lt;a href="https://flow.org/en/docs/lang/subtypes/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Perhaps you previously used &lt;code&gt;$Subtype&lt;/code&gt; to refine component props, &lt;a href="https://github.com/facebook/flow/commit/d9350718d3e53cdbad1a5739ba95c5f82c0058a7"&gt;as suggested at the time of their deprecation&lt;/a&gt;, you can bring back the refinement using bounded generics. &lt;/p&gt;

&lt;p&gt;Some older version of library definitions from Flow-Typed may raise errors. (For example, we were using Redux v3 before Flow 0.89 that caused unhappiness. However, &lt;a href="https://github.com/flow-typed/flow-typed/pull/3223"&gt;there is already a libdef update in Flow-Typed&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;I felt a bit hairy about them anyway. Now that they're gone, time to feel happy and get rid of them :)&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Changes and fixes around read-only object and array&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible errors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cannot assign &lt;code&gt;42&lt;/code&gt; to &lt;code&gt;x[0]&lt;/code&gt; because read-only arrays cannot be written to.&lt;/li&gt;
&lt;li&gt;Cannot assign &lt;code&gt;array&lt;/code&gt; to &lt;code&gt;problem&lt;/code&gt; because read-only array type [1] is incompatible with array type [2].&lt;/li&gt;
&lt;li&gt;Cannot assign &lt;code&gt;3&lt;/code&gt; to &lt;code&gt;x.a&lt;/code&gt; because property &lt;code&gt;a&lt;/code&gt; is not writable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's great to see that Flow is constantly improving and how. (Plus with a slight hint of humor to read about the fixes on the previous unsoundedness).&lt;/p&gt;

&lt;p&gt;So I've found three changes and fixes around read-only things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read-only arrays cannot be written to with any-typed indexes, &lt;a href="https://github.com/facebook/flow/commit/875cb7a94d22237cb324aa0e896fcf78c99342bf"&gt;commit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This now disallows you to mutate read only arrays. And you may ask, why should I be allowed to mutate them anyway? Turns out previously if the index is of type &lt;code&gt;any&lt;/code&gt; you would have been able to. 🤷🏻‍♀️&lt;/p&gt;

&lt;p&gt;Then there are two more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mixed refines to read-only object under typeof = object, &lt;a href="https://github.com/facebook/flow/commit/0983bd041c6289897c9b33d86e9e14d2b686c2e5"&gt;commit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Mixed refined by array produces $ReadOnlyArray, &lt;a href="https://github.com/facebook/flow/commit/5639532065954e7f66a968af5e68f76a762a9c14"&gt;commit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I do not have a better explanation than the commit messages there. So let me quote:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[Bugbash] Mixed refines to read-only object under typeof = object&lt;/strong&gt;&lt;br&gt;
Summary:&lt;br&gt;
It is not safe to refine &lt;code&gt;mixed&lt;/code&gt; to &lt;code&gt;{[string] : mixed}&lt;/code&gt; because this allows writes of any kind into the refined object, and we don't know what type of values the object holds. The only safe operation is to read &lt;code&gt;mixed&lt;/code&gt; out of the object, so the properties must be read only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bad&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mixed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oops&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// yikes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And the one with arrays:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[Bugbash] mixed refined by array produces&lt;/strong&gt; &lt;code&gt;$ReadOnlyArray&amp;lt;mixed&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Summary:&lt;br&gt;
It is not safe to refine &lt;code&gt;mixed&lt;/code&gt; to &lt;code&gt;Array&amp;lt;mixed&amp;gt;&lt;/code&gt; as this allows for writing arbitrary values to the result of the refinement, and since we only know that the value is an array, we cannot know that it is safe to write a given value to the array. We do know, however, that anything we get out of the array will be &lt;code&gt;mixed&lt;/code&gt;, so it is safe to type it as a &lt;code&gt;$ReadOnlyArray&amp;lt;mixed&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mixed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;problem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;mixed&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;problem&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;bad&lt;/span&gt;&lt;span class="p"&gt;(([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;Infer void before type checking starts for functions without a return statement&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible errors:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I think the possible errors caused by this fix can be quite variable. Here are two I know of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cannot cast &lt;code&gt;x.noReturn()&lt;/code&gt; to number because undefined [1] is incompatible with number [2].&lt;/li&gt;
&lt;li&gt;Cannot shadow proto property &lt;code&gt;yourFunction&lt;/code&gt; [1] because object type [2] is incompatible with undefined [3] in the return value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Commit on Flow codebase: &lt;a href="https://github.com/facebook/flow/commit/7b1798a5443671010bdf9138985ed25cd6d0a9fe"&gt;Infer void early for functions with no explicit return&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If a function does not have a return statement, Flow now infers that to &lt;code&gt;void&lt;/code&gt;. Interestingly, the most common errors that arise after this were regarding &lt;em&gt;shadowing proto property&lt;/em&gt;. Check out the following &lt;a href="https://flow.org/try/#0PTAEAEDMBsHsHcBQBLAtgB1gJwC6gFSgCGAzqAEoCmRAxnpFrKqAORbV0sDciiN0pMgFkAngGEmmAHaUpeSgA8csgCZkqtHADoJGWDLkAefAD5QAb0QBIABZEpK6JTHRkNANYAuUAAoAlKAAvGbmAL48oKCIkbb2js6uHv4W0aBWVjT6JLBOWnAA5j4s-G7ulCoAhCx+PFahvFbsDpRYyZbp7DgArlhSoIYqyABuoPoupYHmODbIJFp2Dk7jHqGgwCbW9aFAA"&gt;Try Flow&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;*&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;  &lt;span class="c1"&gt;// &amp;lt;- {} means an object here&lt;/span&gt;

  &lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clicked!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Fixes are simply to annotate them properly &lt;code&gt;() =&amp;gt; void&lt;/code&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Fix a bug which prevented Flow from asking for required type annotations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This line sounds scary 😱  But I haven't encountered any unhappiness that seems related yet. Will come back here if I do.&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/releases/tag/v0.98.0"&gt;Release notes for 0.98&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/flow/commit/7b1798a5443671010bdf9138985ed25cd6d0a9fe"&gt;Infer &lt;code&gt;void&lt;/code&gt; early for functions with no explicit return&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flow.org/try/#0PTAEAEDMBsHsHcBQBLAtgB1gJwC6gFSgCGAzqAEoCmRAxnpFrKqAORbV0sDciiN0pMgFkAngGEmmAHaUpeSgA8csgCZkqtHADoJGWDLkAefAD5QAb0QBIABZEpK6JTHRkNANYAuUAAoAlKAAvGbmAL48oKCIkbb2js6uHv4W0aBWVjT6JLBOWnAA5j4s-G7ulCoAhCx+PFahvFbsDpRYyZbp7DgArlhSoIYqyABuoPoupYHmODbIJFp2Dk7jHqGgwCbW9aFAA"&gt;Try Flow for error caused by shadowing proto property of mismatched annotation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/flow-typed/flow-typed/pull/3223"&gt;Redux 4 Flow-Typed libdef update&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>flow</category>
      <category>flowtype</category>
    </item>
  </channel>
</rss>
