<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tomáš Konrády on Medium]]></title>
        <description><![CDATA[Stories by Tomáš Konrády on Medium]]></description>
        <link>https://medium.com/@tomaskonrady?source=rss-1f8468799d5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8w_xhGvRXXZymALxV53TQg.png</url>
            <title>Stories by Tomáš Konrády on Medium</title>
            <link>https://medium.com/@tomaskonrady?source=rss-1f8468799d5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:38:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tomaskonrady/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Hooks: Notes Taken]]></title>
            <link>https://medium.com/@tomaskonrady/react-hooks-notes-taken-c42376af3ab0?source=rss-1f8468799d5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c42376af3ab0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[notes]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-redux]]></category>
            <dc:creator><![CDATA[Tomáš Konrády]]></dc:creator>
            <pubDate>Fri, 26 Oct 2018 11:24:33 GMT</pubDate>
            <atom:updated>2018-10-26T13:26:44.296Z</atom:updated>
            <content:encoded><![CDATA[<h3>References</h3><ul><li><a href="https://reactjs.org/docs/hooks-intro.html">React official tutorial</a></li><li><a href="https://github.com/reactjs/rfcs/pull/68">RFC</a></li><li><a href="https://www.npmjs.com/package/eslint-plugin-react-hooks">ESLint plugin</a></li><li><a href="https://egghead.io/playlists/react-hooks-and-suspense-650307f2">Egghead tutorial by Kent C. Dodds</a></li></ul><h4>Installation</h4><pre>yarn add react@next react-dom@next</pre><h3>Basic example</h3><pre>const FriendStatus = ({ id }) =&gt; {<br>  const [isOnline, setIsOnline] = useState(null);</pre><pre>  const handleStatusChange = (status) =&gt; {<br>    setIsOnline(status.isOnline);<br>  }</pre><pre>  useEffect(() =&gt; {<br>    ChatAPI.subscribeToFriendStatus(id, handleStatusChange);</pre><pre>    return () =&gt; {<br>      ChatAPI.unsubscribeFromFriendStatus(id, handleStatusChange);<br>    };<br>  });</pre><pre>  if (isOnline === null) {<br>    return &#39;Loading...&#39;;<br>  }<br>  return isOnline ? &#39;Online&#39; : &#39;Offline&#39;;<br>}</pre><h3>Basic rules</h3><ul><li>Only call Hooks at the top level.</li><li>Only call Hooks from React function components.</li></ul><p><em>See aforementioned ESLint plugin.</em></p><p><strong>So…</strong></p><ul><li>They can’t be used within class components</li><li>They can’t be used in combination with for, if, ... as they relies on an order in which they are called.</li></ul><h3>useState</h3><p>Example</p><pre>const Balloon = ({ initialSize, powerOfBlow }) =&gt; {<br>  const [size, setSize] = useState(initialSize);<br>  <br>  const onBlow = () =&gt; setSize(size + powerOfBlow)</pre><pre>  return &lt;div onClick={onBlow}&gt;Size of the balloon: {size}&lt;/div&gt;;<br>}</pre><p>Syntax:</p><pre>@param {any} Initial state value<br>@returns Pair <br>    - fst {any} Value of state<br>    - snd {function} callback to set new value of state</pre><ul><li>Type of the state can be anything unlike state within class components (in that case object must be used).</li><li>It is encouraged to use multiple useState within a function component, instead of using one single state object as is in class components.</li><li>Possible minification</li></ul><h3>useEffect</h3><p>Example:</p><pre>useEffect(() =&gt; {<br>  document.title = `You clicked ${count} times`;</pre><pre>  return () =&gt; {<br>     document.title = &#39;You have never clicked!&#39;;<br>  }<br>});</pre><p>Syntax:</p><pre>@param {Function} effect Function that is called when component performs DOM changes.<br>@param {Array} shouldApply Array of values that should be checked for changes before applying an effect. If values between renders do not change, the effect is not applied again.</pre><pre>@returns {Function} Cleanup function that is called before a component is unmounted and before new render.</pre><p>Notes:</p><ul><li>For side effects :) DOM, logs, fetching APIs…</li><li>It is called after every render — even the first one.</li><li>Unlike class lifecycle methods the useEffect do not block the browser.</li><li>For blocking effects there is useLayoutEffect.</li></ul><h4>shouldUpdate?</h4><pre>useEffect(() =&gt; {<br>    ChatAPI.subscribeToFriendStatus(props.id, handleStatusChange);</pre><pre>    return () =&gt; {<br>      ChatAPI.unsubscribeFromFriendStatus(props.id, handleStatusChange);<br>    };<br>  }, [props.id]);</pre><ul><li>For checking the shouldApply parameter the shallow compare is used.</li><li>Use [] if you need to use effect just for both didMount and willUnmount phases. It is discouraged.</li></ul><h3>Custom hooks</h3><pre>const useFriendStatus = (id) =&gt; {<br>  const [isOnline, setIsOnline] = useState(null);</pre><pre>  const handleStatusChange = (status) =&gt; {<br>    setIsOnline(status.isOnline);<br>  }</pre><pre>  useEffect(() =&gt; {<br>    ChatAPI.subscribeToFriendStatus(id, handleStatusChange);</pre><pre>    return () =&gt; {<br>      ChatAPI.unsubscribeFromFriendStatus(id, handleStatusChange);<br>    };<br>  });</pre><pre>  return isOnline;<br>}</pre><pre>const FriendStatus = ({ id }) =&gt; {<br>  const isOnline = useFriendStatus(id);</pre><pre>  if (isOnline === null) {<br>    return &#39;Loading...&#39;;<br>  }<br>  return isOnline ? &#39;Online&#39; : &#39;Offline&#39;;<br>}</pre><ul><li>The name of a function starts with use, e.g. useRedux.</li><li>Two components that use the same hooks does not share the same state.</li><li>Use cases: form handling, animation, declarative subscriptions, timers, …</li></ul><h3>Other Hooks</h3><h4>useCallback</h4><pre>const memoizedCallback = useCallback(<br>  () =&gt; {<br>    doSomething(a, b);<br>  },<br>  [a, b],<br>);</pre><ul><li>Bye, bye <a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#withhandlers">withHandlers</a> 😝</li></ul><h4>useReducer</h4><pre>const reducer = (state, action) =&gt; {<br>  switch (action.type) {<br>    case &#39;reset&#39;:<br>      return {count: action.payload};<br>    case &#39;increment&#39;:<br>      return {count: state.count + 1};<br>    case &#39;decrement&#39;:<br>      return {count: state.count - 1};<br>  }<br>}</pre><pre>const [state, dispatch] = useReducer(<br>  reducer,<br>  initialState,<br>  { type: &#39;reset&#39;, payload: initialCount },<br>);</pre><h4>useRef &amp;&amp; useImperativeMethods</h4><ul><li>Another way to use refs…</li></ul><h3>React-redux</h3><ul><li>Use React.useReducer for local state</li><li>Use ReactRedux.useRedux for global state</li></ul><pre>import * as actions from &#39;./actions&#39;</pre><pre>const Counter = () =&gt; {<br>  const [count, {increment, decrement}] = useRedux(state =&gt; state.count, actions);<br>  <br>  return (<br>    &lt;Fragment&gt;<br>      Count: {count}<br>      &lt;button onClick={() =&gt; increment()}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; decrement()}&gt;-&lt;/button&gt;<br>    &lt;/Fragment&gt;<br>  );<br>}</pre><ul><li><a href="https://github.com/reduxjs/react-redux/issues/1063">Issue for hooks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c42376af3ab0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compute Even Digits — Fun with Ramda pt.1]]></title>
            <link>https://medium.com/@tomaskonrady/compute-even-digits-fun-with-ramda-pt-1-17fd41d382d2?source=rss-1f8468799d5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/17fd41d382d2</guid>
            <category><![CDATA[fun]]></category>
            <category><![CDATA[ramda]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomáš Konrády]]></dc:creator>
            <pubDate>Sat, 22 Jul 2017 21:02:27 GMT</pubDate>
            <atom:updated>2017-10-06T08:07:22.177Z</atom:updated>
            <content:encoded><![CDATA[<p>I had a free evening. So I gave myself a “challenge”. I wanted to program pretty difficult function that computes a number of even digits in the number.</p><p>So how did I end up to solve that quest?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a430cd8c9b9339833091c80fff6349b/href">https://medium.com/media/4a430cd8c9b9339833091c80fff6349b/href</a></iframe><p>Seriously though.</p><p>I just like how Ramda/functional style makes you create small reusable functions as you can see in the example above. For the pretty straightforward task, I’ve created 5 reusable functions excluding <em>countEvenDigit</em> itself.</p><p>Do you have similar examples? Or do you love Ramda as well? Please share in the comments :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17fd41d382d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>