<?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 iqbal siddik on Medium]]></title>
        <description><![CDATA[Stories by iqbal siddik on Medium]]></description>
        <link>https://medium.com/@iqballsiddik?source=rss-93d0a0b37806------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aFLxq4FZlsfj27Wv</url>
            <title>Stories by iqbal siddik on Medium</title>
            <link>https://medium.com/@iqballsiddik?source=rss-93d0a0b37806------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:36:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iqballsiddik/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[Overcoming Nested Objects in React Javascript With Immer]]></title>
            <link>https://insight.akarinti.tech/overcoming-nested-objects-in-react-javascript-with-immer-d3d175e39a9e?source=rss-93d0a0b37806------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3d175e39a9e</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nested-objects]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[iqbal siddik]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 16:06:17 GMT</pubDate>
            <atom:updated>2025-01-07T16:06:17.605Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Immer?</h3><p>Immer is a JavaScript library that allows you to work with immutable state updates using a “mutative” API. Instead of manually creating new state objects, Immer lets you modify the state draft directly and then produces the next immutable state.</p><h3>Benefits of Using Immer in React</h3><ul><li>Simplifies complex state updates.</li><li>Ensures immutability without boilerplate.</li><li>Improves code readability.</li><li>Works seamlessly with React hooks such as useState and useReducer.</li></ul><h3>Installation</h3><p>To get started, install Immer via npm or yarn:</p><pre>npm install immer<br># or<br>yarn add immer</pre><h3>Example: Using Immer with useState</h3><p>Immer works well with React’s useState hook for managing local component state. Here&#39;s a basic example:</p><pre>import React, { useState } from &#39;react&#39;;<br>import { produce } from &#39;immer&#39;;<br><br>function TodoApp() {<br>  const [todos, setTodos] = useState([<br>    { id: 1, text: &#39;Learn React&#39;, completed: false },<br>    { id: 2, text: &#39;Learn Immer&#39;, completed: false },<br>  ]);<br><br>  const toggleTodo = (id) =&gt; {<br>    setTodos((currentTodos) =&gt;<br>      produce(currentTodos, (draft) =&gt; {<br>        const todo = draft.find((t) =&gt; t.id === id);<br>        if (todo) {<br>          todo.completed = !todo.completed;<br>        }<br>      })<br>    );<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Todo List&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {todos.map((todo) =&gt; (<br>          &lt;li key={todo.id}&gt;<br>            &lt;label&gt;<br>              &lt;input<br>                type=&quot;checkbox&quot;<br>                checked={todo.completed}<br>                onChange={() =&gt; toggleTodo(todo.id)}<br>              /&gt;<br>              {todo.text}<br>            &lt;/label&gt;<br>          &lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default TodoApp;</pre><h4>Key Points in the Code:</h4><ul><li>The produce function creates a draft state that you can &quot;mutate&quot;.</li><li>Immer ensures that the original state remains unchanged.</li></ul><h3>Example: Using Immer with useReducer</h3><p>Immer can simplify reducers by handling immutable updates internally. Here’s how to use it with useReducer:</p><pre>import React, { useReducer } from &#39;react&#39;;<br>import { produce } from &#39;immer&#39;;<br><br>const initialState = {<br>  count: 0,<br>};<br><br>function reducer(state, action) {<br>  return produce(state, (draft) =&gt; {<br>    switch (action.type) {<br>      case &#39;increment&#39;:<br>        draft.count += 1;<br>        break;<br>      case &#39;decrement&#39;:<br>        draft.count -= 1;<br>        break;<br>      case &#39;reset&#39;:<br>        draft.count = 0;<br>        break;<br>      default:<br>        break;<br>    }<br>  });<br>}<br><br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;increment&#39; })}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;decrement&#39; })}&gt;Decrement&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;reset&#39; })}&gt;Reset&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><h4>Key Points in the Code:</h4><ul><li>The reducer function uses produce to handle state updates immutably.</li><li>Immer reduces boilerplate code, especially in reducers with complex logic.</li></ul><h3>Best Practices</h3><ol><li><strong>Use Immer for Nested State</strong>: Immer shines when managing deeply nested state structures.</li><li><strong>Combine with Hooks</strong>: Use Immer with useState for local state or useReducer for more complex state management.</li><li><strong>Avoid Overusing</strong>: While Immer is powerful, use it judiciously to maintain clean and understandable code.</li></ol><h3>When Not to Use Immer</h3><ul><li>For simple state updates (e.g., setCount(count + 1)), Immer might introduce unnecessary complexity.</li><li>If performance is critical, benchmark your application to ensure Immer’s proxy mechanism doesn’t introduce overhead.</li></ul><h3>Conclusion</h3><p>Immer is a great addition to your React toolkit, especially when managing complex state updates. By reducing boilerplate and ensuring immutability, it helps you focus on writing cleaner and more maintainable code. Start integrating Immer into your React applications and experience the benefits of simplified state management!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3d175e39a9e" width="1" height="1" alt=""><hr><p><a href="https://insight.akarinti.tech/overcoming-nested-objects-in-react-javascript-with-immer-d3d175e39a9e">Overcoming Nested Objects in React Javascript With Immer</a> was originally published in <a href="https://insight.akarinti.tech/">Akar Inti Teknologi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Reactive State in Vue 3: A Comprehensive Guide]]></title>
            <link>https://medium.com/@iqballsiddik/understanding-reactive-state-in-vue-3-a-comprehensive-guide-565d8aface04?source=rss-93d0a0b37806------2</link>
            <guid isPermaLink="false">https://medium.com/p/565d8aface04</guid>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[iqbal siddik]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 03:43:22 GMT</pubDate>
            <atom:updated>2024-07-12T03:43:22.185Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*_X3gGizj6G6U-antaq4OuA.png" /></figure><p>Vue 3 introduces a powerful reactivity system that significantly improves the way developers manage and manipulate reactive states in their applications. This guide will explore the key differences and enhancements in Vue 3’s reactive state management compared to its predecessor, Vue 2.</p><h4>1. Introduction to Reactivity in Vue</h4><p>Reactivity is a core concept in Vue.js, enabling the framework to automatically update the DOM whenever the state of the application changes. Vue 2 used an Object.defineProperty-based reactivity system, whereas Vue 3 adopts a new reactivity system based on Proxies. Understanding these differences can help developers leverage the full power of Vue 3 in their applications.</p><h4>2. Composition API</h4><p>The most significant change in Vue 3 is the introduction of the Composition API, which provides a more flexible and reusable way to compose logic inside components.</p><p><strong>Vue 2 (Options API)</strong>:</p><pre>export default {<br>  data() {<br>    return {<br>      count: 0<br>    }<br>  },<br>  methods: {<br>    increment() {<br>      this.count++<br>    }<br>  }<br>}</pre><p><strong>Vue 3 (Composition API)</strong>:</p><pre>import { ref } from &#39;vue&#39;<br><br>export default {<br>  setup() {<br>    const count = ref(0)<br>    const increment = () =&gt; {<br>      count.value++<br>    }<br>    return {<br>      count,<br>      increment<br>    }<br>  }<br>}</pre><h4>3. ref and reactive</h4><p>Vue 3 introduces ref and reactive to handle reactive state in a more intuitive and granular way.</p><p><strong>ref</strong>: Used to create a reactive reference to a single value.</p><pre>import { ref } from &#39;vue&#39;<br><br>const count = ref(0)<br>console.log(count.value) // 0<br>count.value++<br>console.log(count.value) // 1</pre><p><strong>reactive</strong>: Used to create a reactive object that deeply proxies its properties.</p><pre>import { reactive } from &#39;vue&#39;<br><br>const state = reactive({<br>  count: 0<br>})<br>console.log(state.count) // 0<br>state.count++<br>console.log(state.count) // 1</pre><h4>4. Reactivity in Computed Properties</h4><p>Vue 3 enhances computed properties by allowing them to be used in the Composition API, offering more flexibility in their declaration and usage.</p><p><strong>Vue 2 </strong>:</p><pre>export default {<br>  data() {<br>    return {<br>      count: 0<br>    }<br>  },<br>  computed: {<br>    doubleCount() {<br>      return this.count * 2<br>    }<br>  }<br>}</pre><p><strong>Vue 3 </strong>:</p><pre>import { ref, computed } from &#39;vue&#39;<br><br>export default {<br>  setup() {<br>    const count = ref(0)<br>    const doubleCount = computed(() =&gt; count.value * 2)<br>    return {<br>      count,<br>      doubleCount<br>    }<br>  }<br>}</pre><h4>5. Watchers</h4><p>The Composition API in Vue 3 provides a new way to watch for changes in reactive data using the watch function, which can be more intuitive and powerful.</p><p><strong>Vue 2 </strong>:</p><pre>export default {<br>  data() {<br>    return {<br>      count: 0<br>    }<br>  },<br>  watch: {<br>    count(newVal, oldVal) {<br>      console.log(`Count changed from ${oldVal} to ${newVal}`)<br>    }<br>  }<br>}</pre><p><strong>Vue 3 </strong>:</p><pre>import { ref, watch } from &#39;vue&#39;<br><br>export default {<br>  setup() {<br>    const count = ref(0)<br>    watch(count, (newVal, oldVal) =&gt; {<br>      console.log(`Count changed from ${oldVal} to ${newVal}`)<br>    })<br>    return {<br>      count<br>    }<br>  }<br>}</pre><h4>6. Performance Improvements</h4><p>Vue 3’s reactivity system is designed with performance in mind, leveraging Proxy-based reactivity for more efficient change detection and reducing the overhead of tracking dependencies.</p><ul><li><strong>Proxy-based Reactivity</strong>: Allows for more granular tracking of changes and reduces the need for deep reactivity checks, making state updates more efficient and scalable.</li></ul><h4>7. TypeScript Support</h4><p>Vue 3 has improved TypeScript support, making it easier for developers to work with typed reactive state.</p><ul><li><strong>Enhanced Type Inference</strong>: The use of ref and reactive with TypeScript provides better type inference and allows for more robust type-checking in reactive data.</li></ul><h4>Conclusion</h4><p>Vue 3’s reactive state management brings significant improvements and new paradigms to the table. The Composition API, along with ref and reactive, offers more flexibility and power, making it easier for developers to create scalable and maintainable applications. The enhancements in performance, computed properties, watchers, and TypeScript support further solidify Vue 3 as a modern, efficient framework for building reactive web applications.</p><p>Sorry if there are any mistakes or unclear explanations, because I’m still learning Vue3 at an early stage. Happy reading everyone!</p><p>Regards,</p><p>Iqbal Siddik</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=565d8aface04" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>