<?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 Nishtha Bhatia on Medium]]></title>
        <description><![CDATA[Stories by Nishtha Bhatia on Medium]]></description>
        <link>https://medium.com/@nb2998?source=rss-16efe909f9a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0nohA7abO8-bP1T1MV97Kg@2x.jpeg</url>
            <title>Stories by Nishtha Bhatia on Medium</title>
            <link>https://medium.com/@nb2998?source=rss-16efe909f9a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 06:43:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nb2998/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[ReactJS: State management using Redux ToolKit]]></title>
            <link>https://nb2998.medium.com/reactjs-state-management-using-redux-toolkit-c23ca842a925?source=rss-16efe909f9a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c23ca842a925</guid>
            <category><![CDATA[react-redux-toolkit]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[react-redux-devtools]]></category>
            <category><![CDATA[react-state-management]]></category>
            <dc:creator><![CDATA[Nishtha Bhatia]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 12:47:05 GMT</pubDate>
            <atom:updated>2025-04-27T12:47:05.153Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <a href="https://nb2998.medium.com/reactjs-state-management-across-components-part-1-d8d75909ce39">last post</a>, we delved into the foundational concepts of state management and looked at how Apollo’s useReactiveVar works. If you haven’t checked it out yet, I recommend reading it first. Today, we are moving forward in our ReactJS State Management Series to a powerful and popular tool — Redux ToolKit. Stay tuned as we dive into why and how Redux ToolKit can make managing state in ReactJS much simpler.</p><p>Before we begin, do install the <a href="https://chromewebstore.google.com/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en">Redux DevTools Chrome extension</a>. This extension is extremely helpful and helps in development and debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*5Xtt265PVSOPCm86oSyQrA.png" /></figure><p>Let’s dive into the code. Using Redux Toolkit involves four key steps to effectively manage state in your React applications:</p><ol><li><strong>Create a Redux Store</strong>: This is where you set up and configure your centralized store that holds the state of your application.</li><li><strong>Create Slices</strong>: These are modules that contain the state and reducers in one place. They help in organizing the state management related to a specific feature or functionality.</li><li><strong>Update Slices</strong>: Modify or update the slices through actions to reflect the changes in the state based on user interactions or other events.</li><li><strong>React to State Updates</strong>: Use mechanisms within your components to respond to state changes, such as enabling or disabling buttons, displaying data, or triggering other actions in the UI.</li></ol><h3>Step 1: Create a Redux Store</h3><p>Start by installing the following dependencies-</p><ol><li>reduxjs/toolkit</li><li>react-redux</li></ol><p>If you are using yarn as the package manager, you can do so by using the following commands:</p><pre>yarn add reduxjs/toolkit<br>yarn add react-redux</pre><p>Then, create a file store.tsin your src/app or src/ts folder:</p><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br><br>export const createAndConfigureNewStore = () =&gt; {<br>  return configureStore({<br>    reducer: {<br>        // TBD<br>    }<br>  });<br>};</pre><p>Consider a scenario where we’re developing a user registration form for an application. This form is divided into two primary sections: the ContactInfo section and the MedicalInfo section. Below these informational input sections, we have an Actions area which includes the Submit button.</p><figure><img alt="Sample Registration form" src="https://cdn-images-1.medium.com/max/716/1*oiwRfMFrZC1rxxjD6xNtXw.png" /></figure><h3>Step 2: Create slices</h3><p>You can divide your state into logical ‘slices’ inside this store.</p><blockquote>A “slice” is a collection of Redux reducer logic and actions for a feature in your application, typically defined together in a single file. The name comes from splitting up the root Redux state object into multiple “slices” of state.</blockquote><p>This is an crucial step as part of your detailed design to focus on the structure of the store and how to split your store into smaller slices. Slices help to store the states separately into logical pieces.</p><p>For our example, let us create 2 slices- contactInfoSlice and medicalInfoSlice.</p><p>Here is how the contactInfoSlice looks like:</p><pre>import { createSlice } from &quot;@reduxjs/toolkit&quot;;<br><br>export interface ContactInfoState {<br>  name: string | null;<br>}<br><br>export const initialState: ContactInfoState = {<br>  name: null,<br>};<br><br>const contactInfoSlice = createSlice({<br>  name: &quot;contactInfo&quot;,<br>  initialState,<br>  reducers: {<br>    updateContactInfo: (state, action) =&gt; {<br>      state.name = action.payload.name;<br>    },<br>    // more actions can be added here<br>  },<br>});<br><br>export const { updateContactInfo } = contactInfoSlice.actions;<br>export default contactInfoSlice.reducer;</pre><p>As illustrated, each slice includes three critical elements:</p><ol><li><strong>Structure Definition</strong>: We specify the format of the slice through the ContactInfoState interface, which aids in maintaining type safety across components.</li><li><strong>Initial State Values</strong>: Outlined in initialState, these values represent the state prior to any actions or updates being initiated.</li><li><strong>Reducers Specification</strong>: In this example, we’ve developed a reducer containing an action to update the contact information. More actions, such as resetting contact information, could be added to further enhance functionality.</li></ol><p>Following this structure, the medicalInfoSlice is similarly organized as follows:</p><pre>import { createSlice } from &quot;@reduxjs/toolkit&quot;;<br><br>export interface MedicalInfoState {<br>  bloodGroup: string | null;<br>}<br><br>export const initialState: MedicalInfoState = {<br>  bloodGroup: null,<br>};<br><br>const medicalInfoSlice = createSlice({<br>  name: &quot;medicalInfo&quot;,<br>  initialState,<br>  reducers: {<br>    updateMedicalInfo: (state, action) =&gt; {<br>      state.bloodGroup = action.payload.name;<br>    },<br>  },<br>});<br><br>export const { updateMedicalInfo } = medicalInfoSlice.actions;<br>export default medicalInfoSlice.reducer;</pre><p>Finally, we will instantiate the reducers from both the slices in the store:</p><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import medicalInfoReducer from &#39;./slices/medicalInfoSlice&#39;;<br>import contactInfoReducer from &#39;./slices/contactInfoSlice&#39;;<br><br>export const createAndConfigureNewStore = () =&gt; {<br>  return configureStore({<br>  reducer: {<br>    contactInfo: contactInfoReducer,<br>    medicalInfo: medicalInfoReducer,<br>  });<br>};</pre><h3>Step 3: Update Slices</h3><p>We need to make sure our slices always reflect the latest data a user has entered. For instance, changes to the name in the contact information should update the contactInfoSlice, and changes to the blood group should be reflected in the medicalInfoSlice. For these updates, we will employ the useDispatch() hook offered by Redux.</p><p>To streamline this process, let’s create a file named hooks.ts. In this file, we&#39;ll define and export our custom hook named useAppDispatch(). This will help us manage dispatching actions within our application efficiently.</p><pre>import { useDispatch} from &quot;react-redux&quot;;<br><br>export const useAppDispatch = () =&gt; useDispatch&lt;any&gt;();</pre><p>First, let’s manage the updates by ‘dispatching’ the ‘action’ — updateContactInfo()—in the onBlur event handler of the contact name field. To perform this dispatch, we&#39;ll utilize the useAppDispatch() hook that we defined in the hooks.ts file. This will handle the action dispatch when the user moves away from the contact name input field.</p><p>Here’s what the component will look like after these changes:</p><pre>import { ReactDOM } from &quot;react&quot;;<br>import { useAppDispatch } from &quot;../../app/store/hooks&quot;;<br>import { updateContactInfo } from &quot;../../app/store/slices/contactInfoSlice&quot;;<br><br>export default ContactInfoComponent = (props: any) =&gt; {<br>  const dispatch = useAppDispatch();<br><br>  const handleOnBlurName = (event: any) =&gt; {<br>    const { value } = event.target;<br>    dispatch(updateContactInfo({ name: value }));<br>  };<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Contact information&lt;/h1&gt;<br>      &lt;label&gt;Name: &lt;/label&gt;<br>      &lt;input<br>        name=&quot;myInput&quot;<br>        placeholder=&quot;Enter name&quot;<br>        onBlur={handleOnBlurName}<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><p>Similarly, we will dispatch the updateMedicalInfo() action from the medicalInfoSlice in the onBlur event handler of the MedicalInfoComponent.</p><pre>import { ReactDOM } from &quot;react&quot;;<br>import { useAppDispatch } from &quot;../../app/store/hooks&quot;;<br>import { updateMedicalInfo } from &quot;../../app/store/slices/medicalInfoSlice&quot;;<br><br>export default MedicalInfoComponent = (props: any) =&gt; {<br>  const dispatch = useAppDispatch();<br><br>  const handleOnBlurBloodgroup = (event: any) =&gt; {<br>    const { value } = event.target;<br>    dispatch(updateMedicalInfo({ bloodGroup: value }));<br>  };<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Medical information&lt;/h1&gt;<br>      &lt;label&gt;Blood group: &lt;/label&gt;<br>      &lt;input<br>        name=&quot;myInput&quot;<br>        placeholder=&quot;Enter blood group&quot;<br>        onBlur={handleOnBlurBloodgroup}<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><p>To verify that the states are updating properly, you can utilize the Redux DevTools extension. This tool allows you to view a comprehensive list of all dispatched actions, the payloads associated with each action, the current state, and the changes between the current state and the previous state before an action was dispatched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7e_kUGd9amOy9MWwTq7Zw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gypiZa4qp8zG9Uj7b3QQNQ.png" /></figure><h3>Step 4: React to state updates</h3><p>Finally, let’s explore how we can respond to these state updates. Imagine you have a submit button that you want to keep disabled until all mandatory fields are filled out, and enabled as soon as data is entered in all required fields.</p><p>To achieve this, we will use the useSelector() hook provided by Redux. We&#39;ll add this to our hooks.ts file, similar to how we integrated the useDispatch() hook.</p><pre>import { TypedUseSelectorHook, useDispatch, useSelector } from &quot;react-redux&quot;;<br><br>export const useAppDispatch = () =&gt; useDispatch&lt;any&gt;();<br>export const useAppSelector: TypedUseSelectorHook&lt;any&gt; = useSelector;</pre><p>Let’s set up an Actions.tsx component that includes the Submit button. This component should re-render whenever there are changes to contactInfoState or medicalInfoState, and the Submit button should be disabled or enabled based on these updates.</p><p>To retrieve the latest value of the name from contactInfoState, we can use the hook as follows:</p><pre>const { name } = useAppSelector((state) =&gt; state.contactInfoState);</pre><p>Similarly, MedicalInfoState can be accessed in the same manner. Below is how the Actions component is structured:</p><pre>import { ReactDOM } from &quot;react&quot;;<br>import { useAppSelector } from &quot;../../app/store/hooks&quot;;<br><br>export default Actions = (props: any) =&gt; {<br>  const { name } = useAppSelector((state) =&gt; state.contactInfoState);<br>  const { bloodGroup } = useAppSelector((state) =&gt; state.medicalInfoState);<br><br>  const handleOnClick = (event: any) =&gt; {<br>    // Handle click functionality here<br>  };<br><br>  const isDataComplete = () =&gt; {<br>    return name != null &amp;&amp; bloodGroup != null;<br>  };<br><br>  return (<br>    &lt;button onClick={handleOnClick} disabled={!isDataComplete()}&gt;<br>      Submit<br>    &lt;/button&gt;<br>  );<br>};</pre><p>You can further enhance this to add validators for every field to enable the button only when all data is valid.</p><p>In conclusion, utilizing the Redux Toolkit in React applications greatly simplifies state management, ensuring that components like the Actions.tsx can dynamically respond to user input. By effectively employing hooks like useDispatch() and useSelector(), developers can efficiently manage and access the application state, leading to a more organized and maintainable codebase.</p><p>Using above examples of how to integrate and use these hooks within components demonstrates the practical application of Redux Toolkit in a real-world scenario. For those interested in exploring the code further and trying out more functionalities, the entire codebase can be referenced on <a href="https://codesandbox.io/p/sandbox/react-typescript-forked-y5l5jy">here</a>, encouraging hands-on practice with the Redux Toolkit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c23ca842a925" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ReactJS: State management across components- Part 1]]></title>
            <link>https://nb2998.medium.com/reactjs-state-management-across-components-part-1-d8d75909ce39?source=rss-16efe909f9a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8d75909ce39</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nishtha Bhatia]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 17:35:55 GMT</pubDate>
            <atom:updated>2023-06-04T17:35:55.688Z</atom:updated>
            <content:encoded><![CDATA[<p>A state can be managed within a component using the ‘useState’ hook or this.setState({…}) for functional and class-based components respectively. In a simple application, each component maintains its own state and communicates with other components via props, hence there is no need to manage state across components.</p><p>However, as the application and the number of components grow, there arises a need for global state management due to the following reasons:</p><ol><li>Deep nesting of components- Say there are 4 components- A, B, C and D.</li></ol><figure><img alt="Component hierarchy example: D is a child component of C, C is a child component of B, and finally B is a child component of A" src="https://cdn-images-1.medium.com/max/600/1*06EckHATZMzVvkOJNYL0DQ.png" /><figcaption>Nested Components example</figcaption></figure><p>Component A has a variable ‘name’ and Component D needs to display ‘name’ but B and C do not. If global state management is not done, A will have to pass the ‘name’ B which will be passed to C, and C will finally pass it to D. This is called prop drilling. B and C had no need of ‘name’ but had to be passed via them.</p><p>2. Reactiveness- Let us take another example consisting of 5 components as below-</p><figure><img alt="Component A is the top most component. A has 2 child components B and C. That is, B and C are sibling components. B has a child component D while C has a child component E." src="https://cdn-images-1.medium.com/max/600/1*SXdqcKXwakffrRcMYgv3ew.png" /><figcaption>Component structure</figcaption></figure><p>Say component D has a state ‘address’ and component E shows the total price. If the address changes, component E must recalculate the taxes and show the updated amount. Essentially, component E needs to react to any changes to the state belonging to component D.</p><p>Now that we know why we need it, there are multiple ways to manage state in a React application. Some examples are the ‘useContext’ hook, Redux framework or Apollo. The approach you use to manage the global state depends entirely on your use case and application.</p><p>Let us dive deep into <a href="https://www.apollographql.com/docs/react/local-state/reactive-variables/">Apollo’s ‘useReactiveVar’,</a> a hook provided by Apollo that provides the ability to create/update a global variable such that other components can react to it. If you are new to React Hooks, I suggest you read <a href="https://nb2998.medium.com/react-js-decoding-hooks-3cec6bf1d937">this</a> article first and come back.</p><blockquote>useReactiveVar was introduced by Apollo in version 3 so it will not be supported in lower versions. If you are already using Apollo, ensure that you are on version 3 or above.</blockquote><p>The best way to learn anything new- a Counter app. Lets begin!</p><h3><strong>Step 1- Creating a global variable</strong></h3><p>The ‘<strong>makeVar’</strong> method is used to create a new global variable.</p><pre>import {makeVar} from &#39;@apollo/client&#39;<br><br>export const counter = makeVar({<br>  isValid: false,<br>  value: 0,<br>})</pre><p>The above code creates a global variable consisting of 2 attributes ‘isValid’ and ‘value’ that can be accessed across components. While ‘value’ is the value of the counter, ‘isValid’ is used to indicate if the counter value is greater than 0.</p><h3>Step 2- Updating a global variable</h3><p>The makeVar method that we used above actually returns a function that can be used to update the global state. So, all we need to do to update the attributes ‘isValid’ and ‘value’ is to call the function counter and pass the new object to it.</p><p>Let us create 2 buttons to increment/decrement the counter value.</p><pre>const Component1 = () =&gt; {<br>  const {value} = useReactiveVar(counter)<br>  const handleIncreaseOnClick = () =&gt; {<br>    const newCount = value + 1<br>    counter({<br>      isValid: newCount &gt; 0,<br>      value: newCount,<br>    })<br>  }<br><br>  const handleDecreaseOnClick = () =&gt; {<br>    const newCount = value - 1<br>    counter({<br>      isValid: newCount &gt; 0,<br>      value: newCount,<br>    })<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={handleIncreaseOnClick}&gt;Increase counter&lt;/button&gt;<br>      &lt;button onClick={handleDecreaseOnClick}&gt;Decrease counter&lt;/button&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><blockquote>An important thing to note here is, the new object passed to the counter function completely overrides the object stored before. So, always remember to pass all the attributes while updating an object.</blockquote><h3>Step 3- Reacting to a global variable</h3><p><strong>‘useReactiveVar’</strong> is used to react to any changes in the value of a global variable.</p><p>For example, let us create a new component that has a Submit button. The Submit button should be enabled only if counter value is valid (that is, ‘isValid’ attribute is true).</p><pre>const Component3 = () =&gt; {<br>  const {isValid = false} = useReactiveVar(counter)<br>  return (<br>    &lt;&gt;<br>      &lt;button disabled={!isValid} onClick={() =&gt; console.log(&#39;Submit clicked&#39;)}&gt;<br>        Submit<br>      &lt;/button&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>Similarly, if another component needs to display the latest value of counter, it can be done as below-</p><pre>const Component2 = () =&gt; {<br>  const {value} = useReactiveVar(counter)<br>  return (<br>    &lt;&gt;<br>      &lt;span&gt;The count now is {value}&lt;/span&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>Finally, this is how the final application will work-</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Foptimistic-tess-tsj93v%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Foptimistic-tess-tsj93v%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Ftsj93v%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2792d2749d768f7e3f888f6a5204f54/href">https://medium.com/media/d2792d2749d768f7e3f888f6a5204f54/href</a></iframe><p>To access the entire React application code, please follow <a href="https://codesandbox.io/s/optimistic-tess-tsj93v?file=/src/js/apollo/reactiveVariables.js">this</a> link.</p><p>If you like a challenge, try enhancing the application above by adding below-</p><ol><li>Another button to reset the counter to 0</li><li>A new input field for the name and enable Submit button only if the name field is non-empty</li></ol><p>Hope this helped you understand the basics of ‘useReactiveVar’. Do you think you can use this hook in your application? Share your use-case in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8d75909ce39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React JS- Decoding Hooks]]></title>
            <link>https://nb2998.medium.com/react-js-decoding-hooks-3cec6bf1d937?source=rss-16efe909f9a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cec6bf1d937</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[react-lifecycle]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nishtha Bhatia]]></dc:creator>
            <pubDate>Mon, 14 Feb 2022 18:52:11 GMT</pubDate>
            <atom:updated>2022-02-16T05:36:33.227Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Hook?</h3><p>As quoted by the <a href="https://reactjs.org/docs/hooks-intro.html">ReactJs documentation-</a></p><blockquote><em>Hooks</em> are a new addition in React 16.8. They let you use state and other React features without writing a class.</blockquote><p>In other words, Hooks provide an intuitive way to use the React concepts like state, refs, context and lifecycle without the need for classes. They help break complex logic into “separate concerns” while enabling the reuse of stateful logic.</p><p>We will be covering 2 hooks in detail- useState and useEffect.</p><h3>The useState hook</h3><p>As the name suggests, the state hook is used for state management within a component.</p><h4>Syntax</h4><pre>const [myState, setMyState] = useState(initialValue);</pre><p>useState() hook returns an <strong>array</strong> consisting of 2 elements-</p><ul><li>First- The current value of state at an instant</li><li>Second- Function to update the state</li></ul><p>Note: If you see an error like <em>this.setState is not a function</em>, you probably are storing the useState value in an object and not in an array.</p><h4>Using and updating the state</h4><p>Let us understand this with an example. We can handle the opening of a popup (Modal by Bootstrap) with the click of a button and hide it using state management.</p><pre>const MyComponent = (props) =&gt; {<br>  const [showModal, setShowModal] = useState(false);<br>  const handleShow = () =&gt; setShowModal(true);<br>  const handleClose = () =&gt; setShowModal(false);</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;Button onClick={<strong>handleOpen</strong>}&gt;Show popup&lt;/Button&gt;<br>    <br>      &lt;Modal show={<strong>showModal</strong>} onHide={<strong>handleClose</strong>}&gt;<br>        &lt;Modal.Header closeButton&gt;<br>          &lt;Modal.Title&gt;Hello&lt;/Modal.Title&gt;<br>        &lt;/Modal.Header&gt;<br>        &lt;Modal.Body&gt;Have a nice day!&lt;/Modal.Body&gt;<br>        &lt;Modal.Footer&gt;<br>          &lt;Button variant=&quot;primary&quot; onClick={<strong>handleClose</strong>}&gt;<br>            Close<br>          &lt;/Button&gt;<br>        &lt;/Modal.Footer&gt;<br>       &lt;/Modal&gt;<br>    &lt;/&gt;</pre><pre>  );</pre><pre>}</pre><p>On click of the button, the state value changes to true. When a state value changes, the Virtual DOM is updated first (as it is quicker). React then compares the difference between actual and virtual DOM and updates the actual DOM where necessary. In simple words, the show property of Modal becomes true and it appears. Similarly, on clicking the <em>Close</em> button, the <strong>showModal </strong>state is updated to false which makes the Modal disappear.</p><p>If you want to understand behind the scenes in detail, virtual dom diffing has been explained beautifully <a href="https://medium.com/@gethylgeorge/how-virtual-dom-and-diffing-works-in-react-6fc805f9f84e">here</a>.</p><h3>The useEffect Hook</h3><p>The effect hook is used to carry-out side effects in a functional component. In other words, it provides an easy way to perform certain actions in various circumstances once the component mounts. For instance, if something needs to be done when the component renders, or on a state/prop change or there is a cleanup required before unmounting- this hook is to be used. This hook can be understood as a combination of <em>componentDidMount()</em>, <em>componentDidUpdate()</em> and <em>componentWillUnmount()</em> from the class-based components.</p><h4>Syntax</h4><pre>useEffect(() =&gt; {<br>  // Perform the side effects here</pre><pre>});</pre><p>By default, effects run after every successful render. This can however be controlled by accepting an array of dependencies like below-</p><pre>useEffect(() =&gt; {<br>  // Perform the side effects here</pre><pre>}, [dependencyOne, dependencyTwo]);</pre><p>The code inside this effect is triggered when there is a change in the value of any of the dependencies.</p><h4>Managing the React lifecycle</h4><p>The effect code without dependencies is nothing but <strong>componentDidMount()</strong>.<em> </em>The code inside this useffect is triggered as soon as the component mounts.</p><p>As we know, we can also control the execution of code inside useEffect using dependencies. That is, execute the code when there is an update in the value of a dependency. Hence, this can play the role of <strong>componentDidUpdate()</strong><em>. </em>For example, if you want to perform certain validations everytime a state changes, it can be achieved as below-</p><pre>const [data, setData] = useState();</pre><pre>useEffect(()=&gt; {<br>  if(data?.length &gt; 0) {<br>     const isValid = checkDataValid(data);<br>     // act accordingly</pre><pre>  } </pre><pre>}, [data]);</pre><p>Note: Either <em>checkDataValid</em> can be a function created inside the effect or outside the component, or else needs to be passed as a dependency to the effect (This can be a common cause for infinite re-renders).</p><p>Finally, <strong>componentWillUnmount() </strong>can be achieved using the return block inside useEffect. Any unsubscriptions or cleanup should happen here.</p><pre>useEffect(() =&gt; {<br>  return () =&gt; {<br>    // Cleanup<br>  };<br>});</pre><p>These are the two most widely used hooks. There are also various useful hooks like useContext, useCallback, useMemo, etc. You can also create your custom hooks for which the convention is to prefix with ‘use’ (Example- useAction).</p><p>Finally, remember this about hooks-</p><ul><li>A hook can be called from functional components.</li><li>A hook <strong>cannot</strong> be called conditionally but it <strong>can</strong> have conditions. That is, a hook should be there at the top level always and never within a condition/loop.</li><li>A hook can be called from a custom hook.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cec6bf1d937" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WWDC’21- Yay or Nay?]]></title>
            <link>https://nb2998.medium.com/wwdc21-yay-or-nay-ce45079e697e?source=rss-16efe909f9a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce45079e697e</guid>
            <category><![CDATA[wwdc-2021]]></category>
            <category><![CDATA[apple-wwdc-2021]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[ios15]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Nishtha Bhatia]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 09:24:58 GMT</pubDate>
            <atom:updated>2021-06-09T09:24:58.195Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the first time I watched the WWDC event entirely and not just rely on the memes mocking Apple for exaggerating their features. Result? I was blown away! Yes, there were some instances where the feeling of “Why even are they bragging about this!? 😒” came up. But overall, the event was full of surprises for me.</p><figure><img alt="Audience at WWDC- Memojis" src="https://cdn-images-1.medium.com/max/1024/1*uGo2Qwqzx96E11VDTd4HTQ.png" /></figure><p>Spoiler alert for those who were waiting for the new MacBook to be released- it was not. 😞</p><p>Since I am an avid user of MacBook, releases around macOS made me ecstatic. The next release of macOS will be called macOS <strong>Monterey</strong>!!</p><figure><img alt="A picture of macOS Monterey" src="https://cdn-images-1.medium.com/max/1024/1*oUhVxi6SsHh9hycu6n2Fmw.jpeg" /><figcaption>Yayy</figcaption></figure><p><strong>Universal control</strong> was definitely the most prominent feature. It expands continuity to an extent where using the keyboard and trackpad of your Mac, you can control your other Macs and iPads nearby. Is that all? No! You can easily switch between the devices and drag and drop something from one device to the second and second to the third thereby saving the hassle of airdropping. I imagine having Figma open on my mac while designing on another device, that would save the trouble!</p><p>In addition to this, there are two things I am most excited to use for day-to-day work in Monterey. Firstly, the <strong>Shortcuts-</strong>Shortcuts editor will allow linking a series of actions for pre-determined workflows. I expect it would enable me to open my IDE, Postman and play a song for me to set me in the mood for coding- all in a single click⁉️. Secondly, <strong>Safari</strong> redesign. I have always liked Safari because of its battery efficiency and performance unlike Chrome but end up using Chrome as it is more user-friendly and has more intuitive Developer Tools. Safari is getting a redesign making it more natural and uncluttered. Tabs will be more compact and lightweight and tab groups will be introduced. No apparent improvements for the developer tools but still good enough for browsing.</p><p><strong>Shareplay</strong> will also be coming to Monterey along with iOS15. While on a FaceTime call, it will allow you to stream content (from partnered streamers like Disney+), play songs, add songs to a shared queue with your friends!</p><p>Talking about iOS15, <strong>FaceTime</strong> is also adding other features like voice isolation (distinguishing and prioritising speaker’s voice over background noises), portrait mode and sharing links to android users. Also, <strong>Messages</strong> app will be integrated into Photos/Apple music/Safari/other apps. This will mean, you can check up on a link later on Safari that a friend shared when it was not a good time and reference it back to the message to reply. Sounds pretty cool given that all apps would not get cluttered by the spam content.</p><p>My favourite feature of iOS15 would be the redesign of <strong>Photos Memories</strong>. Integration with Apple Music and use intelligence to sync the feel of memory with the song. So, pausing a memory will auto-adjust the pace of memory with the song and changing a song will change the feel of the memory. Words cannot do justice to how awesome the demo looked!</p><p><strong>Live Text</strong> will also be a part of Camera and will be able to recognise text in a picture and take actions. It was not a surprise after using Google Lens all this time.🎃. <strong>Focus mode</strong> will allow customisable modes like a Work mode showing only work-related apps) and intelligent notifications (ordered by priority) will also be there in iOS15.</p><p>They also talked about various fascinating <strong>privacy</strong> updates. iCloud will allow one to add recovery contacts-in case one gets locked out and “Legacy contacts”- to carry forward the digital legacy in case one passes away. Private relay will let you browse on Safari without letting anyone access information about you or the sites you are visiting. Email Privacy Protection is also coming to Mail app that will give you a toggle to disable marketing emails to capture information about you like your IP address. Using Hide my email feature (in iCloud+), unique email addresses will be generated that will forward emails to your own email and can be deleted anytime. I see myself using this to fill up forms/register to websites where I am not really sure about using my primary email address. 👀</p><figure><img alt="A screenshot as part of demo in WWDC to show hide my email feature" src="https://cdn-images-1.medium.com/max/1024/1*mqgAMqFVei5S0IQfrCEtdg.png" /><figcaption>Source: <a href="https://www.apple.com/apple-events/june-2021/">https://www.apple.com/apple-events/june-2021/</a></figcaption></figure><p>There were also features announced around watchOS 8, Home and Apple Maps along with iPadOS 15. For developers, APIs for SharePlay, Focus, RealityKit were also touched upon this year. Check out the details on their <a href="https://www.apple.com/apple-events/june-2021/">official website</a>.</p><p>What was your favourite announcement? Share in the comments! 😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce45079e697e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google I/O’21 Keynote TLDR;]]></title>
            <link>https://nb2998.medium.com/google-i-o21-keynote-tldr-8af533a8699b?source=rss-16efe909f9a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8af533a8699b</guid>
            <category><![CDATA[google-io-2021]]></category>
            <category><![CDATA[android-12]]></category>
            <dc:creator><![CDATA[Nishtha Bhatia]]></dc:creator>
            <pubDate>Tue, 18 May 2021 20:19:04 GMT</pubDate>
            <atom:updated>2021-05-18T20:19:04.109Z</atom:updated>
            <content:encoded><![CDATA[<p>Looking for a quick summary of Google I/O Keynote? Here it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucJHCucb9mGgT-IiJcjmtA.png" /></figure><p>This year Google launched a lot of cool stuff. Let’s go over them briefly.</p><p>Google made various launches of useful features in the Google Workspace. Firstly, <strong>Smart Canvas</strong>- A tool that can be used for effective collaboration that enables adding actionable plans, tracking a campaign launch. Companion mode will also be launched in Google Meets along with noise cancellation, auto-adjust camera zoom and lighting. In addition to that, adding the capability of Google Meets directly from Google Docs or Slides thereby collaborating more effectively.</p><p>They also shared about their work around <strong>LaMDA</strong> (Language Model for Dialogue Applications). In their demo, they showed LaMDA conversing as Pluto and Paper Airplane. The conversations were focused to be natural.</p><p>Augmented Reality was yet again a huge focus for this year’s I/O. We all have played with AR animations of animals. <strong>AR animations of people</strong> are also coming soon! The demo involved various routines of Simone Biles, an American artistic gymnast right in front of you using AR. Augmented reality of maps was taken to the next level by achieving live view expansion using key landmarks, navigation inside buildings and <strong>detailed street maps.</strong> It includes sidewalks for pedestrians, customising the details to an extent that if you are looking at the maps at 8 am, open bakeries will be shown or if you are a tourist, landmarks and tourist sites could be easily seen. <strong>Area busyness</strong> is yet another feature that would be convenient to understand the right time to go depending on how busy the area is.</p><p>Evidently, the <strong>Android 12</strong> design got divulged. The most personal OS ever emphasises security, privacy and enabling all devices to work together. One of the things that I am really excited about is a custom pallet based on wallpaper/lock screen pictures. Dominant, complementary and well-suited colours will be extracted and used as the theme. It will also have an intuitive notification shade and privacy dashboard that will help you manage all app permissions in one place.</p><p>Some new AI-powered features in <strong>Google Photos</strong> comprise of little patterns- identifying not so obvious patterns translating photos into numbers such that set of 3 or more photos and collect into a pattern and creating a memory out of it. Also, synthesizing movements between duplicate photos and creating frames that lead to cinematic moments.</p><p><strong>Innovation in Shopping</strong>- They create a shopping graph based on data from websites, prices, videos and retailers/brands. Opening a new tab on Chrome will soon open carts containing items that you added in the last couple of weeks.</p><p><strong>Inclusive photography</strong> was one of the highlights for me. They are working on an inclusive camera that controls auto white exposure and prevent hampering the pictures due to saturation/contrast/brightness for people of colour.</p><p>Some other innovations mentioned were about the <strong>TPU v4</strong> (Tensor processing unit) promised to be 2X faster than TPU v3, <strong>error-corrected logical QBit</strong> (with a goal to reach error-corrected Quantum computer) and MUM or Multitask Unified Model- 1000X more powerful than BERT.</p><p>Yet another astonishing revelation was the collaboration of Samsung and Google to build a combined platform for <strong>WearOS</strong>.</p><p>I/O ended with the demo of <strong>Project Starline</strong> which is still in the early stages. It will give the 3D experience of meeting someone as if they are right in front of you. It uses high-resolution cameras, custom depth sensors, novel compression and data compression techniques.</p><p>Like every year, the Google I/O was full of surprises. I touched upon some of the features and launches that I found interesting briefly, do check out the official Keynote for detailed information!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8af533a8699b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>