<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammed Iliass Affani</title>
    <description>The latest articles on DEV Community by Mohammed Iliass Affani (@mohammediliassaffani).</description>
    <link>https://dev.to/mohammediliassaffani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2821632%2Fa6019c77-650c-4b91-a376-e80eef4493fa.jpeg</url>
      <title>DEV Community: Mohammed Iliass Affani</title>
      <link>https://dev.to/mohammediliassaffani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohammediliassaffani"/>
    <language>en</language>
    <item>
      <title>🚀 Simplifying State Management in React with useReducer!</title>
      <dc:creator>Mohammed Iliass Affani</dc:creator>
      <pubDate>Mon, 10 Feb 2025 14:51:50 +0000</pubDate>
      <link>https://dev.to/mohammediliassaffani/simplifying-state-management-in-react-with-usereducer-g11</link>
      <guid>https://dev.to/mohammediliassaffani/simplifying-state-management-in-react-with-usereducer-g11</guid>
      <description>&lt;p&gt;When your React components get more complex, managing state with just useState can get messy. This is where &lt;code&gt;useReducer&lt;/code&gt; shines! It’s great for handling more complex state logic.&lt;br&gt;
🔹 Example: Managing a counter with &lt;code&gt;useReducer&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useReducer } from "react";

const initialState = { count: 0 };

function reducer(state, action) {
  switch (action.type) {
    case "increment":
      return { count: state.count + 1 };
    case "decrement":
      return { count: state.count - 1 };
    default:
      throw new Error();
  }
}

function Counter() {
  const [state, dispatch] = useReducer(reducer, initialState);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {state.count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: "increment" })}&amp;gt;+&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: "decrement" })}&amp;gt;-&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why use  &lt;code&gt;useReducer&lt;/code&gt;?&lt;br&gt;
🔄 Simplifies complex state logic&lt;br&gt;
🔧 Makes state management predictable&lt;br&gt;
🚀 Scales better with larger components&lt;br&gt;
💡 Have you tried &lt;code&gt;useReducer&lt;/code&gt; in your projects? Share your experience or any tips you have! 👇&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>vite</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Boost Your React Performance with useMemo</title>
      <dc:creator>Mohammed Iliass Affani</dc:creator>
      <pubDate>Wed, 05 Feb 2025 21:36:21 +0000</pubDate>
      <link>https://dev.to/mohammediliassaffani/boost-your-react-performance-with-usememo-hc5</link>
      <guid>https://dev.to/mohammediliassaffani/boost-your-react-performance-with-usememo-hc5</guid>
      <description>&lt;p&gt;🚀 Boost Your React Performance with useMemo!&lt;/p&gt;

&lt;p&gt;We all know that React can re-render components unnecessarily, which can degrade performance. One way to optimize this is by using useMemo to memoize expensive calculations.&lt;/p&gt;

&lt;p&gt;🔹 Why useMemo?&lt;br&gt;
useMemo helps by caching the result of expensive functions, so they are recalculated only when necessary.&lt;/p&gt;

&lt;p&gt;Example: Efficiently Calculating the Sum of an Array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMemo } from "react";

const numbers = [1, 2, 3, 4, 5];

const sum = useMemo(() =&amp;gt; {
  console.log("Calculating sum...");
  return numbers.reduce((a, b) =&amp;gt; a + b, 0);
}, [numbers]);

console.log(sum); // The sum is calculated only when numbers change!

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why use useMemo?&lt;br&gt;
✅ Prevents unnecessary recalculations&lt;br&gt;
✅ Improves component performance&lt;br&gt;
✅ Helps in large-scale applications&lt;br&gt;
💬 Have you used useMemo in your projects? Let me know how it helped you!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>nestjs</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
