<?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 Nitish Kumar on Medium]]></title>
        <description><![CDATA[Stories by Nitish Kumar on Medium]]></description>
        <link>https://medium.com/@nitishkr88?source=rss-3082a58c8937------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tKRVsJNAMAy7QvV_S9mHfQ.jpeg</url>
            <title>Stories by Nitish Kumar on Medium</title>
            <link>https://medium.com/@nitishkr88?source=rss-3082a58c8937------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:57:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitishkr88/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[Adding OAuth 2.0 support to GraphQL Playground]]></title>
            <link>https://medium.com/@nitishkr88/adding-oauth-2-0-support-to-graphql-playground-6d254278f636?source=rss-3082a58c8937------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d254278f636</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[okta]]></category>
            <category><![CDATA[prisma]]></category>
            <dc:creator><![CDATA[Nitish Kumar]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 03:48:35 GMT</pubDate>
            <atom:updated>2019-10-01T03:48:35.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*N92whqyVYZjzb8_rTEhsgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*ao9TeVBKAkDmFMCr1Eu1Rg.png" /></figure><p><a href="https://github.com/prismagraphql/graphql-playground">GraphQL Playground</a> is a graphical, interactive, in-browser GraphQL IDE. It can be enabled either directly in <a href="https://www.apollographql.com/docs/apollo-server/testing/graphql-playground/#enabling-graphql-playground-in-production">apollo server </a>or can be added as a <a href="https://github.com/prisma-labs/graphql-playground/tree/master/packages/graphql-playground-middleware-express">middleware</a> in your express app. Compared to <a href="https://github.com/graphql/graphiql">GraphiQL</a>, it comes with some extra list of features like:</p><ul><li>Interactive, multi-column schema documentation</li><li>Automatic schema reloading</li><li>Support for GraphQL Subscriptions</li><li>Query history</li><li>Configuration of HTTP headers</li><li>Tabs</li></ul><p>It is extremely useful in the development lifecycle as it enables us to analyse schemas/documentation and formulate queries and mutations. Also, it is a way to provide an auto-generated documentation of our API to the outside world.</p><p>Any production application need to have access control and security around its APIs so that there is restricted data exposure, updates and deletions. As there is no out of the box access management in the Playground, we’d need to enable it somehow.</p><p>OAuth 2.0 is widely used as an industry standard protocol for authorisation. We can chose from a wide varieties of access management providers. This article focuses on <a href="https://www.okta.com/"><strong><em>Okta</em></strong></a> as one such vendor. Same set of principles can be applied to an application developed with other OAuth providers as well.</p><p>An OAuth 2.0 request usually contains a Bearer token with client id as part of http headers. Token value usually is a big hexadecimal string which gets generated once the Okta server authenticates the request. Okta uses a bearer token for API authentication with a sliding scale expiration. They are valid for 30 days and automatically refresh with each API call.</p><p>GraphQL Playground provides ability to manually edit the security headers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFVFihN_LpWF2Z93pfmtoA.png" /></figure><p>You would have figured out by now that manually generating tokens and pasting it to every request can very quickly become tedious and irritating and can lead to less adoption of our API. So, how can the playground generate and set tokens when it is loaded?</p><p>The good folks at Prisma have shipped a React library, <a href="https://github.com/prisma-labs/graphql-playground/tree/master/packages/graphql-playground-react"><strong>graphql-playground-react</strong> </a>which can be leveraged to build our own secured playground(with a few limitations).It uses Redux to manage it’s state. Luckily, we have access to its store and guess what? there is an action which can be dispatched to update the header !🎉</p><h3>Implementation Detail</h3><p>We will be using React hooks in the demonstration. If you are not familiar with hooks, please go through the <a href="https://reactjs.org/docs/hooks-intro.html">documentation</a>. Also, we will be using <a href="https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react">Okta React SDK</a> which comes out of the box with support for react-router and <a href="https://tools.ietf.org/html/rfc6749#section-1.3.2">OAuth 2.0 Implicit Flow</a>.</p><blockquote>Refer this <a href="https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react#usage">link</a> to get details of okta-react usage.</blockquote><h4>Dependencies and Limitations</h4><p>We’d need to import <em>Open Sans</em> and <em>Source Code Pro</em> fonts and <a href="https://github.com/prisma-labs/graphql-playground/blob/master/packages/graphql-playground-react/src/index.css">css</a> provided by graphql-playground.</p><p>For fonts, add this link to the index.html of your app.</p><pre>&lt;link href=&quot;https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700&quot; rel=&quot;stylesheet&quot;&gt;</pre><p>As we’d also need to resolve version conflicts for few libraries, <strong>Yarn</strong> need to be used as the package manager. There are limitations on the usage of versions of <em>redux</em> and <em>graphql</em> as well. Our <em>package.json</em> would look something like below.</p><blockquote><em>npm install</em> is not going to work.</blockquote><pre>&quot;dependencies&quot;: {<br>  &quot;@okta/okta-react&quot;: &quot;^1.2.0&quot;,<br>  &quot;graphql&quot;: &quot;^0.12.0&quot;,<br>  &quot;graphql-playground-react&quot;: &quot;^1.7.20&quot;,<br>  &quot;react-redux&quot;: &quot;^5.0.6&quot;,<br>  &quot;react-router-dom&quot;: &quot;^4.3.1&quot;,<br>  &quot;redux&quot;: &quot;^3.7.2&quot;,<br>  &quot;subscriptions-transport-ws&quot;: &quot;0.9.7&quot;<br>},<br>&quot;resolutions&quot;: {<br>  &quot;graphql&quot;: &quot;0.12.0&quot;,<br>  &quot;subscriptions-transport-ws&quot;: &quot;0.9.7&quot;<br>}</pre><h4>Entry Point</h4><p>We will be passing store to the Redux Provider and supply Okta with the OpenID Connect client configurations. react-router routes setup will also be done here.</p><pre>import React from &#39;react&#39;<br>import ReactDOM from &#39;react-dom&#39;<br>import { BrowserRouter as Router, Route, Switch } from &#39;react-router-dom&#39;<br>import { SecureRoute } from &#39;@okta/okta-react&#39;<br>import { Provider } from &#39;react-redux&#39;<br>import { store } from &#39;graphql-playground-react&#39;<br>import Callback from &#39;@okta/okta-react/dist/ImplicitCallback&#39;</pre><pre>import Security from &#39;./auth/Security&#39;<br>import GqlPlayground from &#39;./gql-playground&#39;</pre><pre>import &#39;./index.css&#39;</pre><pre>ReactDOM.render(<br>  &lt;Provider store={store}&gt;<br>    &lt;Router&gt;<br>      &lt;Security<br>        issuer={`${process.env.OKTA_ORG_URL}/oauth2/default`}<br>        redirect_uri={`${window.location.origin}/implicit/callback`}<br>        client_id={process.env.OKTA_CLIENT_ID}<br>      &gt;<br>        &lt;Switch&gt;<br>          &lt;Route path=&quot;/implicit/callback&quot; component={Callback} /&gt;<br>          &lt;SecureRoute path=&quot;/&quot; component={GqlPlayground} /&gt;<br>        &lt;/Switch&gt;<br>      &lt;/Security&gt;<br>    &lt;/Router&gt;<br>  &lt;/Provider&gt;,<br>  document.getElementById(&#39;app&#39;)<br>)</pre><p>Okta Context initialises and passes down the <em>auth</em> object down the tree. <strong>Security</strong> component allows you to supply your OpenID Connect client configuration.</p><pre>import React from &#39;react&#39;<br>import { withRouter } from &#39;react-router-dom&#39;<br>import { Security as OktaSecurity, Auth } from &#39;@okta/okta-react&#39;</pre><pre>export const OktaContext = React.createContext()</pre><pre>class Security extends React.Component {<br>  render() {<br>    return (<br>      &lt;OktaContext.Provider value={{ auth: new Auth(this.props) }}&gt;        <br>        &lt;OktaSecurity {...this.props} /&gt;<br>      &lt;/OktaContext.Provider&gt;<br>    )<br>  }<br>}</pre><pre>export default withRouter(Security)</pre><h4>Auth Hook</h4><p>Let’s create a react hook(<strong><em>useAuth</em></strong>) which when called returns the current authentication state. The state may include fields like <em>loading, error, authenticated, user, accessor functions</em>, etc. You can also use the <strong><em>withAuth</em></strong> HOC in place of this hook.</p><pre>import { useState, useEffect, useContext } from &#39;react&#39;<br>import { OktaContext } from &#39;./Security&#39;</pre><pre>const useOktaContext = () =&gt; {<br>  return useContext(OktaContext)<br>}</pre><pre>const useAuth = () =&gt; {<br>  const { auth } = useOktaContext()<br>  const [authenticated, setAuthenticated] = useState(null)<br>  const [user, setUser] = useState(null)<br>  const [error, setError] = useState(false)</pre><pre>  useEffect(() =&gt; {<br>    auth.isAuthenticated().then(isAuthenticated =&gt; {<br>      if (isAuthenticated !== authenticated) {<br>        setAuthenticated(isAuthenticated)<br>      }<br>    })<br>  })</pre><pre>const [loading, setLoading] = useState(true)</pre><pre>useEffect(() =&gt; {<br>  if (authenticated) {<br>    auth.getUser()<br>        .then(setUser)<br>        .then(() =&gt; setLoading(false))<br>        .catch(() =&gt; {<br>          setLoading(false)<br>          setError(true)<br>       })<br>  } else { <br>    setUser(null)<br>  }<br>}, [authenticated, auth])</pre><pre>return { ...auth, loading, error, authenticated, user }<br>}</pre><h4>Redux Action</h4><pre>import { createAction } from &#39;redux-actions&#39;</pre><pre>const EDIT_HEADERS = &#39;EDIT_HEADERS&#39;</pre><pre>export const editHeaders = createAction(EDIT_HEADERS, headers =&gt; ({ headers }))</pre><h4>Our own GQL Playground Component</h4><pre>import React, { useState, useEffect } from &#39;react&#39;<br>import { connect } from &#39;react-redux&#39;<br>import { Playground } from &#39;graphql-playground-react&#39;</pre><pre>import { editHeaders } from &#39;./redux/actions&#39;<br>import { useAuth } from &#39;./auth/useAuth&#39;</pre><pre>const GqlPlayground = props =&gt; {<br>  const { editHeaders } = props<br>  <br>  const auth = useAuth()<br>  const [token, setToken] = useState()<br>  const [headers, setHeaders] = useState(props.headers)<br>  const [loading, setLoading] = useState(true)</pre><pre>  useEffect(() =&gt; {<br>    if (!auth.loading) {<br>      auth.getAccessToken().then(setToken)<br>    }<br>  }, [auth])</pre><pre>  useEffect(() =&gt; {<br>    if (token) {<br>      setHeaders({<br>        authorization: `Bearer ${token}`,<br>        client_id: process.env.OKTA_CLIENT_ID<br>      })<br>    }<br>  }, [token])</pre><pre>  useEffect(() =&gt; {<br>    if (headers) {<br>      // this is where the magic happens<br>      editHeaders(JSON.stringify(headers, null, 2))</pre><pre>      setTimeout(() =&gt; {<br>        setLoading(false)<br>      }, 3000)<br>    }<br>  }, [headers])</pre><pre>return (<br>  &lt;&gt;<br>    {loading &amp;&amp; (<br>      &lt;div className=&quot;spinner-wrapper&quot;&gt;<br>        &lt;div className=&quot;spinner-node&quot; /&gt;<br>      &lt;/div&gt;<br>    )}<br>    &lt;Playground endpoint={process.env.SERVICE_URL} /&gt;<br>  &lt;/&gt;<br>  )<br>}</pre><pre>export default connect(<br>  null,<br>  { editHeaders }<br>)(GqlPlayground)</pre><p>Notice the usage of <strong><em>setTimeout</em></strong> above. It is a hack to ensure that we wait for sometime before dismissing the loading Spinner(this wait time is not a guarantee that the schema loading has finished). I’m doing this because we can’t determine if the schema has been loaded, as it is maintained in a state variable inside the Playground component, and we can’t have our middleware injected to intercept the <strong><em>SCHEMA_FETCHING_SUCCESS</em></strong> action as we only get the final created store.</p><p><strong>Spinner css used</strong></p><pre>.spinner-wrapper {<br>  position: absolute;<br>  z-index: 1;<br>  top: 0;<br>  left: 0;<br>  right: 0;<br>  bottom: 0;<br>  height: 100%;<br>  background-color: rgba(185, 191, 196, 0.35);<br>}</pre><pre>.spinner-wrapper .spinner-node {<br>  position: absolute;<br>  top: 50%;<br>  left: 50%;<br>  display: inline-block;<br>  height: 48px;<br>  width: 48px;<br>  vertical-align: middle;<br>  animation: rotation 0.6s infinite linear;<br>  border-radius: 100%;<br>  border-bottom: 6px solid rgba(150, 150, 150, 0.15);<br>  border-left: 6px solid rgba(150, 150, 150, 0.15);<br>  border-right: 6px solid rgba(150, 150, 150, 0.15);<br>  border-top: 6px solid rgba(150, 150, 150, 0.8);<br>}</pre><pre>@keyframes rotation {<br>  from {<br>    transform: rotate(0deg);<br>  }<br>  to {<br>    transform: rotate(359deg);<br>  }<br>}</pre><p>On running the application, you will be redirected to the Okta login screen. Signing in successfully would in turn navigate to the home page after a series of redirection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*dLaC_A-nNrnEDIOd.png" /></figure><h4><strong>Redux Dev tools snippet</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8d_JPs7qes_qVLL3vHFTcg.png" /></figure><h4><strong>Headers successfully set</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hp6c1kIuA6sb1Pf0t1TrqQ.png" /></figure><p>References</p><ul><li><a href="https://developer.okta.com/code/react/">https://developer.okta.com/code/react/</a></li><li><a href="https://itnext.io/injecting-a-client-side-script-in-graphql-playground-in-apollo-server-d23b6e3c901b">https://itnext.io/injecting-a-client-side-script-in-graphql-playground-in-apollo-server-d23b6e3c901b</a></li></ul><p><strong><em>P.S. If the article helped you, make sure to clap👏 , follow me on </em></strong><a href="https://twitter.com/nitishk88"><strong><em>twitter</em></strong></a><strong><em>, and share with your friends!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d254278f636" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React setState usage and gotchas]]></title>
            <link>https://itnext.io/react-setstate-usage-and-gotchas-ac10b4e03d60?source=rss-3082a58c8937------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac10b4e03d60</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[setstate]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nitish Kumar]]></dc:creator>
            <pubDate>Sat, 10 Mar 2018 09:40:54 GMT</pubDate>
            <atom:updated>2018-04-01T12:27:06.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*1EdhEzJOw80RPWj64ydsAA.jpeg" /></figure><blockquote><a href="https://www.linkedin.com/cws/share?url=https%3A%2F%2Fitnext.io%2Freact-setstate-usage-and-gotchas-ac10b4e03d60%3Futm_source%3Dmedium_sharelink%26utm_medium%3Dsocial%26utm_campaign%3Dbuffer"><em>Click here to share this article on LinkedIn</em></a></blockquote><p>A React class component has an internal state which like props affects how the component renders and behaves. Unlike props, state is local to the component and can only be initialised and updated within the component.</p><h3><strong>Initialisation</strong></h3><p>Before we can use state, we need to declare a default set of values for the initial state. This can be done by either creating a state object in the constructor or directly within the class.</p><pre>class Counter extends React.Component {<br>  constructor(props, context) {<br>    super(props, context)<br>    this.state = {<br>      quantity: 1,<br>      counter: 0<br>    }<br>  }<br>}</pre><pre>class Counter extends React.Component {<br>  state = {<br>    quantity: 1,<br>    counter: 0<br>  }<br>}</pre><h3><strong>Update</strong></h3><p>State can be updated in response to event handlers, server responses or prop changes. React provides a method called setState for this purpose.</p><p>setState() enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated state.</p><pre>this.setState({quantity: 2})</pre><p>Here, we passed setState() <strong>an object</strong> containing part(s) of the state we wanted to update. The object passed would have keys corresponding to the keys in the component state, then setState() updates or sets the state by merging the object to the state.</p><h3><strong>setState and re-rendering</strong></h3><p>setState() will always lead to a re-render unless shouldComponentUpdate() returns false. To avoid unnecessary renders, calling setState() only when the new state differs from the previous state makes sense and can avoid calling setState() in an infinite loop within certain lifecycle methods like componentDidUpdate.</p><blockquote>React 16 onwards, calling setState with null no longer triggers an update. This means we can decide if the state gets updated within our setState method itself!</blockquote><h3><strong>Signature</strong></h3><pre>setState(updater[, callback])</pre><p>The first argument is an updater function with the signature:</p><pre>(prevState, props) =&gt; stateChange</pre><p>prevState is a reference to the previous state. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from prevState and props. For example, to increment a value in state by props.step:</p><pre>this.setState((prevState, props) =&gt; {<br>  return {counter: prevState.counter + props.step};<br>})</pre><blockquote>Due to the async nature of setState, it is not advisable to use this.state to get the previous state within setState. Instead, always rely on the above way. Both prevState and props received by the updater function are guaranteed to be up-to-date. The output of the updater is shallowly merged with prevState.</blockquote><p>The second parameter to setState() is an optional callback function that will be executed once setState is completed and the component is re-rendered. componentDidUpdate should be used instead to apply such logic in most cases.</p><p>You may directly pass an object as the first argument to setState instead of a function. This performs a shallow merge of the state change into the new state.</p><pre>this.setState({quantity: 2})</pre><h3>Batching state updates</h3><p>In case multiple setState() calls are made, React may batch the state updates while respecting the order of updates. Currently (React 16 and earlier), <strong>only updates inside React event handlers are batched by default</strong>. Changes are always flushed together at the end of the event and you don’t see the intermediate state.</p><p>It doesn’t matter how many<strong> </strong>setState()<strong> </strong>calls in how many components you do inside a React event handler, they will produce only a single re-render at the end of the event. For example, if child and parent each call setState() when handling a click event, the child would only re-render once.</p><p>Till React 16, <strong>there is no batching by default outside of React event handlers</strong>. So, each setState() would be processed immediately as it happens if they lie outside any event handler. For example:</p><pre>promise.then(() =&gt; {<br>  // We&#39;re not in an event handler, so these are flushed separately.<br>  this.setState({a: true}); // Re-renders with {a: true, b: false }<br>  this.setState({b: true}); // Re-renders with {a: true, b: true }<br>})</pre><p>However, ReactDOM provides an api which could be used to force batch updates.</p><pre>promise.then(() =&gt; {<br>  // Forces batching<br>  ReactDOM.unstable_batchedUpdates(() =&gt; {<br>    this.setState({a: true}); // Doesn&#39;t re-render yet<br>    this.setState({b: true}); // Doesn&#39;t re-render yet<br>  });<br>  // When we exit unstable_batchedUpdates, re-renders once<br>})</pre><p>Internally React event handlers are all wrapped in unstable_batchedUpdates due to which they&#39;re batched by default. Wrapping an update in unstable_batchedUpdates twice has no effect. The updates are flushed when the outermost unstable_batchedUpdates call exits.</p><blockquote>The API is “unstable” in the sense that it will be removed when batching is already enabled by default in the React core.</blockquote><h3>Declaring state changes outside of React Component</h3><p>This section is inspired by the below tweet from Dan Abramov.</p><h3>Dan Abramov on Twitter</h3><p>Best kept React secret: you can declare state changes separately from the component classes.</p><p>As setState expects a function in the argument, the function can be implemented somewhere outside of the React Class and then imported and used inside the Component as the argument to setState. In case extra arguments are needed, higher order functions can come to the rescue.</p><pre>const multiplyBy = multiplier =&gt; state =&gt; ({<br>  value: state.value * multiplier<br>})</pre><p>As state updates are now plain JavaScript, testing complex state transitions won’t involve shallow rendering of React components.</p><h3>Dan Abramov on Twitter</h3><p>Declaring state updates as pure functions makes it a breeze to test complex state transitions. Even no need for shallow rendering!</p><h3>setState and Lifecycle methods</h3><p>Calling setState in lifecycle methods requires a level of caution. There are a few methods where it doesn’t make sense to call setState and there are a few where it should be called conditionally. Let’s take it case by case.</p><h4>componentWillMount</h4><p>setState can be called here. The updated state would be used inside the immediate render as long as it is not calculated based on Promise resolution. It is advised to used componentDidMount for performing any state updates on Promise resolution, etc. The other reason to not use this method is that in the future releases of React(17 onwards), this method is going to be deprecated.</p><p><a href="https://github.com/reactjs/rfcs/blob/master/text/0006-static-lifecycle-methods.md">reactjs/rfcs</a></p><h4>componentDidMount</h4><p>This is the preferred method for async rendering.</p><h4>componentWillReceiveProps</h4><p>The main purpose of this method is to calculate some values derived from props for use during render. Although, if the calculation is fast enough it could just be done in render. setState is perfectly safe to be used here.</p><h4>shouldComponentUpdate</h4><p>This is one of those methods where it doesn’t make sense to update component’s state. It is invoked internally by React during the update phase (props or state change). Calling setState here would result in an infinite loop as it is the next method that it called on updating state. If you need to set state in the props update phase, use componentWillReceiveProps.</p><h4>componentWillUpdate</h4><p>Don’t use setState here. Similar reasons as shouldComponentUpdate.</p><h4>render</h4><p>Calling setState here makes your component a contender for producing infinite loops. render should remain pure and be used to conditionally switch between JSX fragments/child components based on state or props. Callbacks in render can be used to update state and then re-render based on the change.</p><blockquote>If you find yourself having to write setState within render, you may want to rethink the design. In fact, this may be a perfect use-case to implement the state machines pattern.</blockquote><p><a href="https://medium.freecodecamp.org/boost-your-react-with-state-machines-1e9641b0aa43">Boost your React with State Machines</a></p><h4>componentDidUpdate</h4><p>The most common use case for calling setState here is to update the DOM in response to prop or state changes. Here, you wait for the component to get rendered before updating the state again. This makes it a candidate for setting state values which is dependent on the rendered DOM values. Remember to check if you are updating the same state again as this method would be called again after setState() call . For example:</p><pre>componentDidUpdate = (prevProps, prevState) =&gt; {<br>  let width = ReactDOM.findDOMNode(this).parentNode.offsetWidth<br>  if (prevState &amp;&amp; prevState.width !== width) {<br>    this.setState({ width })<br>  }<br>}</pre><h4>componentWillUnmount</h4><p>Don’t use setState here. Your component is going away.</p><p>References</p><ul><li><a href="https://reactjs.org/docs/react-component.html#setstate">https://reactjs.org/docs/react-component.html#setstate</a></li><li><a href="https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates/48610973#48610973">https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates/48610973#48610973</a></li></ul><p><strong><em>P.S. If the article helped you, make sure to clap👏 , follow me on </em></strong><a href="https://twitter.com/nitishk88"><strong><em>twitter</em></strong></a><strong><em>, and share with your friends!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac10b4e03d60" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/react-setstate-usage-and-gotchas-ac10b4e03d60">React setState usage and gotchas</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Immutability in React and Redux]]></title>
            <link>https://medium.com/@nitishkr88/immutability-in-react-and-redux-7137f7b3197?source=rss-3082a58c8937------2</link>
            <guid isPermaLink="false">https://medium.com/p/7137f7b3197</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[immutability]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nitish Kumar]]></dc:creator>
            <pubDate>Fri, 29 Dec 2017 09:19:25 GMT</pubDate>
            <atom:updated>2017-12-29T10:58:44.563Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0kVtEABxP_bAUDDGaBWqCQ.jpeg" /></figure><p><strong><em>According to Redux, you should never mutate the state tree directly. Instead return new state objects by passing the intent (actions) through pure functions (reducers).</em></strong></p><p>Already a mouthful? Let’s take a step back and understand how we compare data structures in JavaScript. Comparing primitive types is pretty straight forward. Just put a === between the variables you want to compare. If the type and value match, they are equal.</p><pre><strong>var</strong> x = 5,<br>    y = 5</pre><pre>x === y // true</pre><p>It is a bit different in case of objects though.</p><pre><strong>var</strong> object1 = { x: 1, y: 2 },<br>    object2 = { x: 1, y: 2 }</pre><pre>object1 === object2 <em>// false</em></pre><p>But they look the same. Why are they not equal 🤔. If you think about equality of things, you can in fact think about two things:</p><ul><li><em>does a thing mean the same as the other thing?</em></li><li><em>is a thing exactly the same thing as the other thing?</em></li></ul><p>For the above objects, they are the same in terms of keys and values but as they are initialised separately, they are not the same in terms of reference. The result would have been different if they would have been pointing to the same address.</p><pre><strong>var</strong> object1 = { x: 1, y: 2 }<br><strong>var</strong> object2 = object1</pre><pre>object1 === object2 <em>// true</em></pre><p>This has some interesting consequences though.</p><pre><strong>object1</strong>.x = 12</pre><pre><strong>object1</strong>.x <em>// 12<br></em><strong>object2</strong>.x <em>// 12</em></pre><p>In this case, we did assign x key of an object object1. But since object1 and object2 points to the same reference, the change is visible through both variables. Every complex data structure in JavaScript follows the principles of reference equality. This includes arrays and objects. In fact, arrays are objects too: <strong>typeof</strong>([1,2,3]) <em>// &quot;object&quot;</em></p><h4><strong>Comparing objects based on values</strong></h4><p>Value equality answers the question: Does a thing mean the same as the other thing?</p><pre><strong>var</strong> object1 = { x: 1, y: 2 }<br><strong>var</strong> object2 = { x: 1, y: 2 }<br><strong>valueEqual</strong>(object1, object2) === true</pre><p>Implementing such equality would be harder with nested data structures. Objects can have arbitrary keys and values. It can contain other objects within them. To make such equality for objects, you’d need to follow the following algorithm:</p><pre>// Input: <strong>object1</strong> and <strong>object2</strong><br>// Output:<br>     <strong>true</strong> if object1 is equal in terms of values to object2<br><br><strong>valueEqual</strong>(object1, object2):<br>  object1keys = &lt;list of keys of object1&gt;<br>  object2keys = &lt;list of keys of object2&gt;<br><br>  return false if length(object1keys) != length(object2keys)<br><br>  for each key in object1keys:<br>    return false if key not in object2keys<br>    return false if typeof(object1[key]) != typeof(object2[key])<br><br>    if object1[key] is an object:<br>      keyEqual = valueEqual(object1[key], object2[key])<br>      return false if keyEqual != false<br><br>    if object1[key] is a primitive:<br>      return false if object1[key] != object2[key]<br><br>  return true</pre><p>For deeply nested structures, it can make thousands of equality checks to compare two objects. Such equality checks are commonly called <a href="https://github.com/lodash/lodash/blob/master/.internal/baseIsEqualDeep.js">deep equality checks</a>.</p><h4><strong>Get rid of mutations</strong></h4><blockquote>Whenever your object would be mutated, don’t do it. Instead, create a changed copy of it</blockquote><p>You can achieve this in a number of ways. Listing a few</p><ul><li>Object.assign({}, …)</li><li>[].concat</li><li>Array.prototype.slice()</li><li>… operator (spread)</li><li>External libraries (ImmutableJS, immutability-helper, icepick, etc.)</li></ul><h4>Using ImmutableJS</h4><p>From the docs:</p><blockquote>Immutable.js provides many Persistent Immutable data structures including: <a href="https://facebook.github.io/immutable-js/docs/#/List">List</a>, <a href="https://facebook.github.io/immutable-js/docs/#/Stack">Stack</a>, <a href="https://facebook.github.io/immutable-js/docs/#/Map">Map</a>, <a href="https://facebook.github.io/immutable-js/docs/#/OrderedMap">OrderedMap</a>, <a href="https://facebook.github.io/immutable-js/docs/#/Set">Set</a>, <a href="https://facebook.github.io/immutable-js/docs/#/OrderedSet">OrderedSet</a> and <a href="https://facebook.github.io/immutable-js/docs/#/Record">Record</a>. These data structures are highly efficient on modern JavaScript VMs by using structural sharing via <a href="http://en.wikipedia.org/wiki/Hash_array_mapped_trie">hash maps tries</a> and <a href="http://hypirion.com/musings/understanding-persistent-vector-pt-1">vector tries</a> as popularised by Clojure and Scala, minimising the need to copy or cache data.</blockquote><p>Seems like something we could use. But lets google some pros and cons before.</p><h4>Pros</h4><ul><li><a href="https://medium.com/@dtinth/immutable-js-persistent-data-structures-and-structural-sharing-6d163fbd73d2">Persistent data structures and structural sharing</a></li><li>Optimized for large datasets and objects</li><li>Mitigates accidental mutations</li><li>Works great if some <a href="https://redux.js.org/docs/recipes/UsingImmutableJS.html#what-are-some-opinionated-best-practices-for-using-immutablejs-with-redux">opinionated best practices are followed</a></li></ul><h4>Cons</h4><ul><li>Difficult to interoperate with. For example, instead of myObj.prop1.prop2.prop3, you would use ImmutableMap.getIn([‘prop1’, ‘prop2’, ‘prop3’])</li><li>Can spread throughout the codebase, as the codebase must know what is, and what is not, an Immutable.JS object</li><li>Difficult to debug (dev tools are available though)</li><li>No De-structuring or Spread Operator support(only if you like them)</li><li>Not suitable for small values that change often</li></ul><p>There are other really good <a href="https://github.com/markerikson/redux-ecosystem-links/blob/master/immutable-data.md#immutable-update-utilities">immutability helpers</a> out there. They have their own benefits and trade-offs though. Listing a few:</p><h4>Pros</h4><ul><li>Seamless interoperability with JavaScript</li><li>Suitable for small and simple JavaScript objects</li><li>Easy to debug</li></ul><h4>Cons</h4><ul><li>Performance issues for big datasets</li><li>API may take time to get familiar with. Code gets harder to read when updating, deleting values using the array like syntax</li></ul><p>Can we create a pure JS library of our own where immutable operations look like mutable ones. This might sound familiar to people using async/await for performing asynchronous actions by writing synchronous looking code or if you are familiar with the go-routines concept in GoLang. Ok, coming back to the topic. Yes, we can try to create something. But, prior to that, I would like to discuss the importance of immutability in a React application.</p><h4>Immutability and ReactJS</h4><ul><li>When state changes, a React component re-renders. React can’t assume anything about your state. That’s why setting state always re-renders the component — even if it’s not necessary at all, as React <a href="https://reactjs.org/blog/2016/01/08/A-implies-B-does-not-imply-B-implies-A.html">doesn’t deeply compare props/state by default</a>. (The implementation is different for Pure components though)</li><li>For a complicated state (nested objects), you’d be forced to make a deep equality check, because when objects are compared using reference equality you can’t be sure whether the next state is changed.</li></ul><blockquote>If you want to optimise React to perform updates only when necessary, you would need to make hundreds of value equality checks if your state is huge</blockquote><h4>shouldComponentUpdate</h4><p>It is a lifecycle optimisation method which allows your Component to exit the Update life cycle if there is no reason to apply a new render</p><ul><li>Out of the box, shouldComponentUpdate() is a no-op that returns true</li><li>Implementation for Pure React components</li></ul><pre>/**<br> * Performs equality by iterating through keys on an object and     returning false<br> * when any key has values which are not strictly equal between the arguments.<br> * Returns true when the values of all keys are strictly equal.<br> */</pre><pre>function <strong>shallowEqual</strong>(objA: mixed, objB: mixed): boolean {<br>  if (objA === objB) {<br>    <strong>return</strong> true<br>  }<br><br>  if (typeof objA !== &#39;object&#39; || objA === null ||<br>      typeof objB !== &#39;object&#39; || objB === null) {<br>    <strong>return</strong> false<br>  }<br><br>  var keysA = Object.keys(objA)<br>  var keysB = Object.keys(objB)<br><br>  if (keysA.length !== keysB.length) {<br>    <strong>return</strong> false<br>  }<br><br>  // Test for A&#39;s keys different from B<br>  var bHasOwnProperty = hasOwnProperty.bind(objB)<br>  for (var i = 0; i &lt; keysA.length; i++) {<br>    if (!bHasOwnProperty(keysA[i]) ||<br>         objA[keysA[i]] !== objB[keysA[i]]) <strong>return</strong> false<br>  }<br><br>  <strong>return</strong> true<br>}</pre><pre>function <strong>shallowCompare</strong>(instance, nextProps, nextState) {<br>  <strong>return</strong> (!shallowEqual(instance.props, nextProps) ||<br>           !shallowEqual(instance.state, nextState))<br>}</pre><pre>function<strong> shouldComponentUpdate</strong>(nextProps, nextState) {<br>  <strong>return</strong> shallowCompare(<strong>this</strong>, nextProps, nextState)<br>}</pre><p>Performing deep equality check within shouldComponentUpdate is not a great idea in case you have a large enough state and props to compare. Sometimes re-rendering can be faster than comparing and escaping re-renders.</p><p>Shallow comparison is easy on eyes, but it uses === to compare objects. If the current state is mutated, it will return true as the reference didn’t change, resulting in no re-render.</p><p>This is why Redux requires pure methods for reducers. If you need to change nested data you have to clone the objects and make sure a new instance is always returned. This allows for shallowCompare() to see the change and update the component. Usage of ImmutableJS and friends enforces immutability at any level in the object. We can leverage the modest === within shouldComponentUpdate() and have it verify that props and state have changed.</p><h4>Going back to Redux <a href="https://redux.js.org/docs/recipes/reducers/ImmutableUpdatePatterns.html">docs</a></h4><p>The key to updating nested data is <strong>that <em>every</em> level of nesting must be copied and updated appropriately</strong>.</p><ul><li><strong>Mistake 1</strong> — New variables that point to the same objects</li><li><strong>Mistake 2</strong> — Only making a shallow copy of one level</li><li><strong>Correct Approach</strong> — Copying All Levels of Nested Data</li></ul><p>The process of correctly applying immutable updates to deeply nested state can easily become verbose and hard to read. Here’s what an example of updating state.first.second[someId].fourth might look like:</p><pre>function <strong>updateVeryNestedField</strong>(state, action) {<br>    return {<br>        ...state,<br>        first : {<br>            ...state.first,<br>            second : {<br>                ...state.first.second,<br>                [action.someId] : {<br>                    ...state.first.second[action.someId],<br>                    fourth : action.someValue<br>                }<br>            }<br>        }<br>    }<br>}</pre><h4>Coming back to creating an immutability helper</h4><p>The issue that we had with some of the helpers out there was the not so obvious api. We wanted something mutable looking but immutable 😎. Lodash provides with a method called toPath which can convert value passed to a property path array.</p><pre>import { toPath } from &#39;lodash&#39;</pre><pre>toPath(&#39;a.b.c&#39;)</pre><pre>// =&gt; [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]</pre><pre>toPath(&#39;a[0].b.c&#39;)</pre><pre>// =&gt; [&#39;a&#39;, &#39;0&#39;, &#39;b&#39;, &#39;c&#39;]</pre><p>If we can leverage this and create a package which can help us implement the above requirement in the below manner, it would be a good start.</p><blockquote>For the bundlesize purists, impact of Lodash to the size of bundle can be aggressively controlled by using <a href="https://github.com/lodash/babel-plugin-lodash">babel-plugin-lodash</a> and <a href="https://github.com/lodash/lodash-webpack-plugin">lodash-webpack-plugin</a></blockquote><pre><strong>import</strong> { setIn } <strong>from</strong> &quot;some-package&quot;</pre><pre>function <strong>updateVeryNestedField</strong>(state, action) {<br>  <strong>const</strong> newState =<br>    setIn(state,<br>      `first.second[${action.someId}].fourth`,<br>        action.someValue)</pre><pre>  console.log(state === newState) <em>// false<br>  </em><strong>return</strong> newState<br>}</pre><pre><strong>import</strong> { deleteIn } <strong>from</strong> &quot;some-package&quot;</pre><pre>function <strong>deleteVeryNestedField</strong>(state, action) {<br>  <strong>const</strong> newState =<br>    deleteIn(state,<br>      `first.second[${action.someId}].fourth`)</pre><pre>  console.log(state === newState) <em>// false<br>  </em><strong>return</strong> newState<br>}</pre><p>Lets try to design the setIn method</p><p>As setIn expects a state which can be an Object or an Array, path string and a value, the signatures can look like below</p><blockquote><a href="https://flow.org/">Flow</a> is used to add type annotations</blockquote><pre><strong>const</strong> setIn = (state: Object | Array&lt;*&gt;, field: string, value: any)  =&gt; setInWithPathArray(state, value, toPath(field), 0)</pre><pre><strong>const</strong> setInWithPathArray = ( state: Object | Array&lt;*&gt;, value: any, path: string[], pathIndex: number): Object | Array&lt;*&gt;</pre><p>setInWithPathArray takes path values as array and the current usable array index, which can be used to traverse the object and reach the final node that need to be updated. We can use a recursive approach by getting the head of the array and calling the function again with the next object(calculated from first key) and remaining path list. The object to be returned can be calculated by using the spread operator with the current object, key to be updated and the state returned by the recursive call.</p><pre><strong>if</strong> (pathIndex &gt;= path.length) {<br>  return value<br>}</pre><pre><strong>const</strong> first = path[pathIndex]</pre><pre><strong>const</strong> firstState = state &amp;&amp; (Array.isArray(state) ?state[Number(first)] : state[first])</pre><pre><strong>const</strong> next = setInWithPathArray(firstState, value, path, pathIndex + 1)</pre><pre><strong>return</strong> { ...state, [first]: next }</pre><p>There are a few edge cases and early returns that need to be handled. Also, other basic methods like deleteIn and getIn could be implemented by following similar approach. For brevity, I would not be explaining them here.</p><p>If you got inspired enough, an immutability helper which solves your purpose is not that hard to make. In case you are feeling lazy, take a look at the library I published.</p><h4><a href="https://www.npmjs.com/package/redux-immutable-ops">redux-immutable-ops</a></h4><h4>API</h4><ul><li>setIn(state: Object | Array&lt;*&gt;, path: string, value: any): Object | Array&lt;*&gt;</li><li>getIn(state: Object | Array&lt;*&gt;, path: string): any</li><li>deleteIn(state: Object | Array&lt;*&gt;, path: string): ?(Object | Array&lt;*&gt;)</li><li>deleteInRecursive(state: Object | Array&lt;*&gt;, path: string): ?(Object | Array&lt;*&gt;)</li><li>pop(array: Array&lt;*&gt;): Array&lt;*&gt;</li><li>other array utilities</li></ul><p><strong><em>If the library helped you, please </em></strong>🌟 <strong>the </strong><a href="https://github.com/nitishkr88/redux-immutable-ops"><strong>repository</strong></a>. <strong><em>If the article helped you, make sure to clap👏 , follow me on </em></strong><a href="https://twitter.com/nitishk88"><strong><em>twitter</em></strong></a><strong><em>, and share with your friends!</em></strong></p><p>References:</p><ul><li><a href="https://redux.js.org/docs/recipes/reducers/ImmutableUpdatePatterns.html">https://redux.js.org/docs/recipes/reducers/ImmutableUpdatePatterns.html</a></li><li><a href="https://medium.com/@dtinth/immutable-js-persistent-data-structures-and-structural-sharing-6d163fbd73d2">https://medium.com/@dtinth/immutable-js-persistent-data-structures-and-structural-sharing-6d163fbd73d2</a></li><li><a href="http://reactkungfu.com/2015/08/pros-and-cons-of-using-immutability-with-react-js/">http://reactkungfu.com/2015/08/pros-and-cons-of-using-immutability-with-react-js/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7137f7b3197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP Retries in Go]]></title>
            <link>https://medium.com/@nitishkr88/http-retries-in-go-e622e51d249f?source=rss-3082a58c8937------2</link>
            <guid isPermaLink="false">https://medium.com/p/e622e51d249f</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Nitish Kumar]]></dc:creator>
            <pubDate>Wed, 27 Dec 2017 11:25:55 GMT</pubDate>
            <atom:updated>2017-12-27T11:25:55.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*qGJssOfn5Hi-Z13jyCObyQ.png" /></figure><p>Building a resilient distributed micro services architecture involves handling certain scenarios like temporary service unavailability, timeouts, and other connection errors with a well thought retry mechanism.</p><p>Go’s net/http client doesn’t provide a retry mechanism by default. In case you need to implement it on your own, there are a few conditions and edge cases which need to be implemented and handled.</p><ul><li>Identify the type of errors based on which retry should be done</li><li>Backing off between attempts</li><li>For requests taking a body (POST, PUT, etc), original payload should be used for every attempt. Any intermediate read should be rewinded back to the start</li><li>Prevent <em>Closing</em> of the request body in case of a retry-able error. <em>Closing</em> btw is the default behaviour 🙁</li><li>Logging between attempts</li><li>etc…</li></ul><p>It is already looking like a task pretty hard to get right in the first few attempts. There are a few libraries which can be considered. But they usually have a complicated interface or a limited set of functionality which may lead to scalability and interoperability issues in a big enough project. It is always better to understand the basics, get inspired by open source implementation(s), and write a library as per your project’s standards.</p><blockquote>Hashicorp’s <a href="https://github.com/hashicorp/go-retryablehttp"><strong>go-retryablehttp</strong></a><strong> </strong>seems to tick most of the check boxes to base our implementation on.</blockquote><p>Breaking down the problem statement into smaller chunks:</p><ul><li><strong>Creating a retry policy </strong>— Different projects may need to implement a bespoke logic of their own to identify retry-able errors. To make it generic across the project, we can export a function type which can be implemented by the application’s client. We can provide a default retry policy which checks for a range of status codes in the response and retry on 500 range responses.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_WId_spJvkCfMk0fQxzuQ.png" /></figure><ul><li><strong>Create a back-off strategy </strong>— A backoff strategy specifies how long to wait between retries. Similar to the retry policy, export a function type and provide a default implementation of the same.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6fHlvADV4N44PuET1wtQBg.png" /></figure><ul><li><strong>Client and Constructor</strong> — Create your own client and it’s constructor based on the already defined settings</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kd7UT7WyEmXXsei4ZP51cw.png" /></figure><ul><li><strong>Rewind <em>Body</em> before retries</strong> — There should be a mechanism to rewind the payload to it’s initial form in between retries. For that, we can base the body on the <em>io.ReadSeeker</em> interface rather than the default <em>io.Reader. </em>The default <em>http.Request</em> can be wrapped together with a <em>body</em> implementing <em>io.ReadSeeker </em>within a new <em>Request</em> type. By embedding the original request directly, we can maintain the same public API.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKon1VXnPGyZFlRYuh3VwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*WrUQKvyrsooHxRiaRg1Eaw.png" /></figure><ul><li><strong>More Wrapping</strong> — <em>http.NewRequest</em> returns a new <em>Request</em> given a method, URL and optional body of type <em>io.Reader</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxp7evnDotHFZXOop81BBQ.png" /></figure><p>We may need to wrap this method with our own implementation 😁. This is necessary as the body passed to this function need to be prevented from getting closed in case of an error; which can be achieved by wrapping the body in a <a href="https://golang.org/pkg/io/ioutil/#NopCloser">no-op ReadCloser</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eG0InkbDxaNlV3vHL7Qxpg.png" /></figure><ul><li><strong>Client.Do</strong> — This is the method where all the work happens. As per the default implementation, it sends an HTTP request and returns a response. The request body, if non-nil, will be closed even on errors. We have already taken care of that by using a no-op wrapper above. What remains is seeking the pointer to the initial position of the body between retries, checking for retry conditions, backing off between retries, consuming the response to reuse the connection, exiting on exhausting the retry attempts, and other pre/post processing(s) 😅.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cszolq6FPJs5pgdp-417KA.png" /></figure><ul><li><strong>Some convenience methods</strong> —</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-Az0HkDeYjMt1_pNWukMQ.png" /></figure><blockquote>That’s all folks !!!</blockquote><p><strong><em>P.S. If the article helped you, make sure to clap👏 , follow me on </em></strong><a href="https://twitter.com/nitishk88"><strong><em>twitter</em></strong></a><strong><em>, and share with your friends!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e622e51d249f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>