<?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 Insafinhaam on Medium]]></title>
        <description><![CDATA[Stories by Insafinhaam on Medium]]></description>
        <link>https://medium.com/@insafinhaam732?source=rss-31b825cf15ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ga5rT-MTCdUjtinuE3Nl_A.jpeg</url>
            <title>Stories by Insafinhaam on Medium</title>
            <link>https://medium.com/@insafinhaam732?source=rss-31b825cf15ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:09:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@insafinhaam732/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[ Advanced React Guide: Performance, Redux, Hooks, Context, and Real-World Projects]]></title>
            <link>https://medium.com/@insafinhaam732/advanced-react-guide-performance-redux-hooks-context-and-real-world-projects-e69fe7e8d2cb?source=rss-31b825cf15ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/e69fe7e8d2cb</guid>
            <dc:creator><![CDATA[Insafinhaam]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 12:09:15 GMT</pubDate>
            <atom:updated>2025-06-07T12:30:50.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oalp-QG-9H-BhCRAZCgcUw.png" /></figure><p>Welcome to the <strong>Advanced React Guide</strong>, designed to help you move beyond the basics and become a proficient React developer. In this guide, we will dive deep into performance optimization techniques, advanced React patterns like hooks, context API, render props, higher-order components, and also how to design robust applications using modern best practices. Let’s get started!</p><h3>✅ Phase 5: Performance Optimization</h3><h3>1. React.memo</h3><p>Memoizes a component to avoid unnecessary re-renders when props don’t change.</p><pre>const MyComponent = React.memo(function MyComponent({ name }) {<br>  return &lt;p&gt;Hello, {name}&lt;/p&gt;;<br>});</pre><h3>2. useMemo</h3><p>Use this hook to memoize expensive calculations.</p><pre>const expensiveValue = useMemo(() =&gt; {<br>  return computeExpensiveValue(input);<br>}, [input]);</pre><h3>3. useCallback</h3><p>Memoize functions passed to child components.</p><pre>const handleClick = useCallback(() =&gt; {<br>  console.log(&quot;Clicked&quot;);<br>}, []);</pre><h3>4. Lazy Loading Components</h3><p>Split code at component level to load only when needed.</p><pre>const LazyComponent = React.lazy(() =&gt; import(&#39;./LazyComponent&#39;));</pre><pre>&lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>  &lt;LazyComponent /&gt;<br>&lt;/Suspense&gt;</pre><h3>5. Virtualization (e.g., react-window)</h3><p>Efficiently render large lists by rendering only visible items.</p><pre>import { FixedSizeList as List } from &#39;react-window&#39;;</pre><pre>&lt;List height={150} itemCount={1000} itemSize={35} width={300}&gt;<br>  {({ index, style }) =&gt; &lt;div style={style}&gt;Row {index}&lt;/div&gt;}<br>&lt;/List&gt;</pre><h3>✅ Phase 6: Advanced React Patterns</h3><h3>1. Context API</h3><p>Share data globally without prop drilling.</p><pre>const ThemeContext = createContext();</pre><pre>function App() {<br>  return (<br>    &lt;ThemeContext.Provider value=&quot;dark&quot;&gt;<br>      &lt;Toolbar /&gt;<br>    &lt;/ThemeContext.Provider&gt;<br>  );<br>}</pre><pre>function Toolbar() {<br>  const theme = useContext(ThemeContext);<br>  return &lt;div className={theme}&gt;Toolbar&lt;/div&gt;;<br>}</pre><h3>2. Custom Hooks</h3><p>Encapsulate logic into reusable functions.</p><pre>function useLocalStorage(key, initialValue) {<br>  const [value, setValue] = useState(() =&gt; {<br>    const stored = localStorage.getItem(key);<br>    return stored ? JSON.parse(stored) : initialValue;<br>  });<br><br>  useEffect(() =&gt; {<br>    localStorage.setItem(key, JSON.stringify(value));<br>  }, [key, value]);<br><br>  return [value, setValue];<br>}</pre><h3>3. Render Props</h3><p>Pass functions as children to share code.</p><pre>function Mouse({ children }) {<br>  const [position, setPosition] = useState({ x: 0, y: 0 });<br><br>  useEffect(() =&gt; {<br>    const handleMouseMove = e =&gt; setPosition({ x: e.clientX, y: e.clientY });<br>    window.addEventListener(&#39;mousemove&#39;, handleMouseMove);<br>    return () =&gt; window.removeEventListener(&#39;mousemove&#39;, handleMouseMove);<br>  }, []);<br><br>  return children(position);<br>}<br><br>&lt;Mouse&gt;<br>  {pos =&gt; &lt;p&gt;The mouse position is {pos.x}, {pos.y}&lt;/p&gt;}<br>&lt;/Mouse&gt;</pre><h3>4. Higher-Order Components (HOCs)</h3><p>Functions that take a component and return a new component.</p><pre>function withLogger(WrappedComponent) {<br>  return function LoggerComponent(props) {<br>    useEffect(() =&gt; {<br>      console.log(&#39;Props:&#39;, props);<br>    }, [props]);<br>    return &lt;WrappedComponent {...props} /&gt;;<br>  };<br>}</pre><h3>✅ Phase 7: Redux (State Management)</h3><ol><li><strong>Install Redux Toolkit and React Redux</strong></li></ol><pre>npm install @reduxjs/toolkit react-redux</pre><ol><li><strong>Create a Slice</strong></li></ol><pre>const counterSlice = createSlice({<br>  name: &#39;counter&#39;,<br>  initialState: { value: 0 },<br>  reducers: {<br>    increment: state =&gt; { state.value += 1 },<br>    decrement: state =&gt; { state.value -= 1 },<br>  }<br>});</pre><ol><li><strong>Configure Store</strong></li></ol><pre>const store = configureStore({<br>  reducer: {<br>    counter: counterSlice.reducer,<br>  },<br>});</pre><ol><li><strong>Use Redux in Component</strong></li></ol><pre>function Counter() {<br>  const count = useSelector(state =&gt; state.counter.value);<br>  const dispatch = useDispatch();<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch(increment())}&gt;+&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>✅ Phase 8: Integration &amp; Real-World Project Design</h3><h3>1. Integrating APIs &amp; Error Handling</h3><pre>function FetchUser() {<br>  const [data, setData] = useState(null);<br>  const [error, setError] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;https://api.example.com/user&#39;)<br>      .then(res =&gt; {<br>        if (!res.ok) throw new Error(&#39;Failed to fetch&#39;);<br>        return res.json();<br>      })<br>      .then(setData)<br>      .catch(setError);<br>  }, []);<br><br>  if (error) return &lt;p&gt;Error: {error.message}&lt;/p&gt;;<br>  if (!data) return &lt;p&gt;Loading...&lt;/p&gt;;<br>  return &lt;p&gt;Hello, {data.name}&lt;/p&gt;;<br>}</pre><h3>2. Retry Logic &amp; Edge Cases</h3><pre>async function fetchWithRetry(url, retries = 3) {<br>  for (let i = 0; i &lt; retries; i++) {<br>    try {<br>      const res = await fetch(url);<br>      if (!res.ok) throw new Error(&#39;Fetch failed&#39;);<br>      return await res.json();<br>    } catch (err) {<br>      if (i === retries - 1) throw err;<br>    }<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e69fe7e8d2cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ React for Beginners]]></title>
            <link>https://medium.com/@insafinhaam732/react-for-beginners-3438ed8a7f3f?source=rss-31b825cf15ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/3438ed8a7f3f</guid>
            <dc:creator><![CDATA[Insafinhaam]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 11:10:13 GMT</pubDate>
            <atom:updated>2025-06-07T12:30:49.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHDri532SIl8Ge0TLJAQQA.png" /></figure><p>Welcome to the first part of our comprehensive React guide tailored for beginners. I’ll walk you through the essential React concepts in an easy-to-understand and structured way. By the end of Phase 4, you should be able to build scalable React applications confidently.</p><h3>✅ Phase 1: Introduction to React</h3><h3>1. What is React?</h3><p>React is a JavaScript library for building <strong>user interfaces</strong>. It allows you to create <strong>reusable UI components</strong> and manage <strong>state</strong> efficiently.</p><ul><li>Developed by Facebook</li><li>Component-based</li><li>Used for Single Page Applications (SPAs)</li></ul><h4>Example:</h4><pre>function Hello() {<br>  return &lt;h1&gt;Hello, React!&lt;/h1&gt;;<br>}</pre><h3>2. Environment Setup</h3><h4>Requirements:</h4><ul><li>Node.js and npm: <a href="https://nodejs.org/">Download</a></li><li>Code Editor: <a href="https://code.visualstudio.com/">VS Code</a></li></ul><h4>Create a React App:</h4><pre>npx create-react-app my-app<br>cd my-app<br>npm start</pre><p>This creates a boilerplate React project with everything configured.</p><h3>3. JSX Basics</h3><p>JSX is a syntax extension that looks like HTML, but is used in JavaScript.</p><h4>Example:</h4><pre>function Greeting() {<br>  const name = &quot;Insaf&quot;;<br>  return &lt;h1&gt;Hello, {name}!&lt;/h1&gt;;<br>}</pre><h4>Rules:</h4><ul><li>Return only one parent element (wrap with &lt;div&gt; or &lt;&gt;)</li><li>Use className instead of class</li><li>JavaScript expressions inside {}</li></ul><h4>Fragment:</h4><pre>return (<br>  &lt;&gt;<br>    &lt;h1&gt;Title&lt;/h1&gt;<br>    &lt;p&gt;Paragraph&lt;/p&gt;<br>  &lt;/&gt;<br>);</pre><h3>✅ Phase 2: Core React Concepts</h3><h3>4. Components</h3><p>React components can be <strong>functional</strong> or <strong>class-based</strong>. We use functional components with hooks.</p><h4>Example:</h4><pre>function Welcome(props) {<br>  return &lt;h1&gt;Hello, {props.name}!&lt;/h1&gt;;<br>}</pre><pre>&lt;Welcome name=&quot;Insaf&quot; /&gt;</pre><h3>5. useState Hook</h3><p>useState is used to add state to functional components.</p><h4>Example:</h4><pre>import { useState } from &#39;react&#39;;</pre><pre>function Counter() {<br>  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>6. Event Handling</h3><p>Events in React are similar to HTML but written in camelCase.</p><h4>Example:</h4><pre>function HandleClick() {<br>  const showMessage = () =&gt; alert(&quot;Button Clicked!&quot;);<br>  return &lt;button onClick={showMessage}&gt;Click&lt;/button&gt;;<br>}</pre><h3>7. Conditional Rendering</h3><p>Show elements based on a condition.</p><h4>Example:</h4><pre>function LoginStatus({ isLoggedIn }) {<br>  return (<br>    &lt;div&gt;<br>      {isLoggedIn ? &lt;p&gt;Welcome back!&lt;/p&gt; : &lt;p&gt;Please log in.&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>8. Lists and Keys</h3><p>Rendering multiple components from an array.</p><h4>Example:</h4><pre>function TodoList() {<br>  const todos = [&#39;Learn React&#39;, &#39;Write Code&#39;, &#39;Read Docs&#39;];<br>  <br>  return (<br>    &lt;ul&gt;<br>      {todos.map((todo, index) =&gt; (<br>        &lt;li key={index}&gt;{todo}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><h3>9. useEffect Hook</h3><p>Used for side effects like data fetching.</p><h4>Example:</h4><pre>import { useEffect, useState } from &#39;react&#39;;</pre><pre>function DataFetcher() {<br>  const [data, setData] = useState(null);</pre><pre>  useEffect(() =&gt; {<br>    fetch(&#39;https://api.example.com/data&#39;)<br>      .then(response =&gt; response.json())<br>      .then(setData);<br>  }, []); // Empty array means run only once</pre><pre>  return &lt;pre&gt;{JSON.stringify(data, null, 2)}&lt;/pre&gt;;<br>}</pre><h3>✅ Phase 3: Intermediate Concepts</h3><h3>10. React Router</h3><p>React Router is used for navigation.</p><pre>npm install react-router-dom</pre><h4>Example:</h4><pre>import { BrowserRouter as Router, Route, Routes, Link } from &#39;react-router-dom&#39;;</pre><pre>function App() {<br>  return (<br>    &lt;Router&gt;<br>      &lt;nav&gt;<br>        &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;<br>        &lt;Link to=&quot;/about&quot;&gt;About&lt;/Link&gt;<br>      &lt;/nav&gt;<br>      &lt;Routes&gt;<br>        &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>        &lt;Route path=&quot;/about&quot; element={&lt;About /&gt;} /&gt;<br>      &lt;/Routes&gt;<br>    &lt;/Router&gt;<br>  );<br>}</pre><h3>11. Forms and Input Handling</h3><h4>Example:</h4><pre>function ContactForm() {<br>  const [name, setName] = useState(&#39;&#39;);<br><br>  const handleSubmit = (e) =&gt; {<br>    e.preventDefault();<br>    alert(`Submitted: ${name}`);<br>  };<br><br>  return (<br>    &lt;form onSubmit={handleSubmit}&gt;<br>      &lt;input value={name} onChange={(e) =&gt; setName(e.target.value)} /&gt;<br>      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>}</pre><h3>12. Lifting State Up</h3><p>Share state between components by moving it to their common parent.</p><h3>✅ Phase 4: Advanced Concepts</h3><h3>13. Context API</h3><p>Use context to share data across multiple components.</p><h4>Example:</h4><pre>const UserContext = React.createContext();</pre><pre>function App() {<br>  return (<br>    &lt;UserContext.Provider value={{ name: &quot;Insaf&quot; }}&gt;<br>      &lt;Profile /&gt;<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}</pre><pre>function Profile() {<br>  const { name } = useContext(UserContext);<br>  return &lt;p&gt;Hello, {name}&lt;/p&gt;;<br>}</pre><h3>14. Custom Hooks</h3><p>Create reusable hooks for cleaner code.</p><h4>Example:</h4><pre>function useCounter(initialValue = 0) {<br>  const [count, setCount] = useState(initialValue);<br>  const increment = () =&gt; setCount(count + 1);<br>  return { count, increment };<br>}</pre><pre>function Counter() {<br>  const { count, increment } = useCounter();<br>  return &lt;button onClick={increment}&gt;Count: {count}&lt;/button&gt;;<br>}</pre><h3>15. Error Boundaries (Class Components)</h3><p>Catch runtime errors in components.</p><pre>class ErrorBoundary extends React.Component {<br>  state = { hasError: false };<br>  static getDerivedStateFromError() {<br>    return { hasError: true };<br>  }<br>  render() {<br>    return this.state.hasError ? &lt;h1&gt;Error occurred.&lt;/h1&gt; : this.props.children;<br>  }<br>}</pre><h3>🛠️ Recommended VS Code Extensions for React Development</h3><ul><li><strong>ESLint</strong> — Lint your JavaScript code</li><li><strong>Prettier</strong> — Format your code automatically</li><li><strong>React Developer Tools</strong> — Debug React components</li><li><strong>Reactjs code snippets</strong> — Faster coding with shortcuts</li><li><strong>Bracket Pair Colorizer 2</strong> — Visual matching of brackets</li><li><strong>GitLens</strong> — Git integration in VS Code</li><li><strong>Tailwind CSS IntelliSense</strong> — For Tailwind users</li><li><strong>Path Intellisense</strong> — Auto-import file paths</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3438ed8a7f3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚓ Mastering React: A Beginner’s Guide to All 13 Built-In Hooks]]></title>
            <link>https://medium.com/@insafinhaam732/mastering-react-a-beginners-guide-to-all-13-built-in-hooks-b5e2f5a25573?source=rss-31b825cf15ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5e2f5a25573</guid>
            <dc:creator><![CDATA[Insafinhaam]]></dc:creator>
            <pubDate>Thu, 29 May 2025 00:43:36 GMT</pubDate>
            <atom:updated>2025-06-07T12:30:48.085Z</atom:updated>
            <content:encoded><![CDATA[<p>React hooks are powerful functions that let you use state and other React features without writing a class. Introduced in React 16.8, hooks simplify code and make it reusable.</p><p>In this guide, we’ll walk you through all <strong>13 built-in React hooks</strong> step by step, with examples and clear explanations, perfect for beginners.</p><h3>1. useState – Managing Component State</h3><p>The useState hook lets you add state to functional components.</p><pre>import { useState } from &#39;react&#39;;</pre><pre>function Counter() {<br>  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ul><li>count is the current state.</li><li>setCount is the function to update it.</li></ul><h3>2. useEffect – Side Effects (API Calls, Timers)</h3><p>useEffect runs after every render. It’s commonly used for fetching data, setting up subscriptions, etc.</p><pre>import { useState, useEffect } from &#39;react&#39;;</pre><pre>function Timer() {<br>  const [time, setTime] = useState(0);</pre><pre>  useEffect(() =&gt; {<br>    const interval = setInterval(() =&gt; {<br>      setTime(prev =&gt; prev + 1);<br>    }, 1000);</pre><pre>    return () =&gt; clearInterval(interval); // Cleanup<br>  }, []);</pre><pre>  return &lt;p&gt;Time: {time}s&lt;/p&gt;;<br>}</pre><ul><li>[] means it runs once when component mounts.</li><li>Return function is a cleanup.</li></ul><h3>3. useContext – Accessing Global State</h3><p>Use context to avoid prop drilling.</p><pre>import { createContext, useContext } from &#39;react&#39;;</pre><pre>const ThemeContext = createContext(&#39;light&#39;);</pre><pre>function ThemedComponent() {<br>  const theme = useContext(ThemeContext);<br>  return &lt;p&gt;Current theme: {theme}&lt;/p&gt;;<br>}</pre><pre>function App() {<br>  return (<br>    &lt;ThemeContext.Provider value=&quot;dark&quot;&gt;<br>      &lt;ThemedComponent /&gt;<br>    &lt;/ThemeContext.Provider&gt;<br>  );<br>}</pre><h3>4. useReducer – Advanced State Management</h3><p>Use this for complex state transitions.</p><pre>import { useReducer } from &#39;react&#39;;</pre><pre>function reducer(state, action) {<br>  switch (action.type) {<br>    case &#39;increment&#39;: return { count: state.count + 1 };<br>    case &#39;decrement&#39;: return { count: state.count - 1 };<br>    default: return state;<br>  }<br>}</pre><pre>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, { count: 0 });</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;p&gt;{state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;increment&#39; })}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &#39;decrement&#39; })}&gt;-&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>5. useCallback – Memoize Functions</h3><p>Avoid re-creating functions unnecessarily.</p><pre>import { useState, useCallback } from &#39;react&#39;;</pre><pre>function App() {<br>  const [count, setCount] = useState(0);</pre><pre>  const handleClick = useCallback(() =&gt; {<br>    console.log(&#39;Clicked&#39;);<br>  }, []);</pre><pre>  return (<br>    &lt;button onClick={handleClick}&gt;Click Me&lt;/button&gt;<br>  );<br>}</pre><h3>6. useMemo – Memoize Values</h3><p>Prevents expensive calculations on every render.</p><pre>import { useState, useMemo } from &#39;react&#39;;</pre><pre>function ExpensiveComponent() {<br>  const [count, setCount] = useState(0);</pre><pre>  const expensiveCalculation = useMemo(() =&gt; {<br>    return count * 1000;<br>  }, [count]);</pre><pre>  return &lt;p&gt;Calculated: {expensiveCalculation}&lt;/p&gt;;<br>}</pre><h3>7. useRef – Persist Values or Access DOM</h3><p>Use it to store mutable values or DOM references.</p><pre>import { useRef } from &#39;react&#39;;</pre><pre>function InputFocus() {<br>  const inputRef = useRef(null);</pre><pre>  function handleClick() {<br>    inputRef.current.focus();<br>  }</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;input ref={inputRef} /&gt;<br>      &lt;button onClick={handleClick}&gt;Focus Input&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>8. useImperativeHandle – Custom Ref Behavior</h3><p>Used with forwardRef to expose instance methods.</p><pre>import { useImperativeHandle, forwardRef, useRef } from &#39;react&#39;;</pre><pre>const CustomInput = forwardRef((props, ref) =&gt; {<br>  const inputRef = useRef();<br>  useImperativeHandle(ref, () =&gt; ({<br>    focus: () =&gt; inputRef.current.focus()<br>  }));</pre><pre>  return &lt;input ref={inputRef} /&gt;;<br>});</pre><pre>function App() {<br>  const inputRef = useRef();</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;CustomInput ref={inputRef} /&gt;<br>      &lt;button onClick={() =&gt; inputRef.current.focus()}&gt;Focus&lt;/button&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>9. useLayoutEffect – DOM Mutations Before Paint</h3><p>Works like useEffect but fires <strong>synchronously</strong> after DOM mutations.</p><pre>import { useLayoutEffect, useRef } from &#39;react&#39;;</pre><pre>function LayoutComponent() {<br>  const ref = useRef();</pre><pre>  useLayoutEffect(() =&gt; {<br>    ref.current.style.color = &#39;red&#39;;<br>  }, []);</pre><pre>  return &lt;p ref={ref}&gt;This text will be red immediately&lt;/p&gt;;<br>}</pre><h3>10. useDebugValue – For Debugging Custom Hooks</h3><p>Used inside custom hooks to label values in React DevTools.</p><pre>import { useDebugValue, useState, useEffect } from &#39;react&#39;;</pre><pre>function useOnlineStatus() {<br>  const [isOnline, setIsOnline] = useState(true);</pre><pre>  useDebugValue(isOnline ? &#39;Online&#39; : &#39;Offline&#39;);</pre><pre>  return isOnline;<br>}</pre><h3>11. useTransition – Mark State Updates as Non-Urgent</h3><p>Improves performance for slow updates.</p><pre>import { useState, useTransition } from &#39;react&#39;;</pre><pre>function SearchComponent() {<br>  const [input, setInput] = useState(&#39;&#39;);<br>  const [list, setList] = useState([]);<br>  const [isPending, startTransition] = useTransition();</pre><pre>  function handleChange(e) {<br>    const value = e.target.value;<br>    setInput(value);<br>    startTransition(() =&gt; {<br>      setList(new Array(10000).fill(value));<br>    });<br>  }</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;input value={input} onChange={handleChange} /&gt;<br>      {isPending &amp;&amp; &lt;p&gt;Loading...&lt;/p&gt;}<br>      &lt;ul&gt;{list.map((item, index) =&gt; &lt;li key={index}&gt;{item}&lt;/li&gt;)}&lt;/ul&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>12. useDeferredValue – Defer Value for Performance</h3><p>Delays updating a value to reduce UI blocking.</p><pre>import { useState, useDeferredValue } from &#39;react&#39;;</pre><pre>function DeferredComponent() {<br>  const [text, setText] = useState(&#39;&#39;);<br>  const deferredText = useDeferredValue(text);</pre><pre>  return (<br>    &lt;&gt;<br>      &lt;input value={text} onChange={(e) =&gt; setText(e.target.value)} /&gt;<br>      &lt;p&gt;{deferredText}&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>13. useId – Generate Unique IDs</h3><p>Helpful for accessibility and SSR.</p><pre>import { useId } from &#39;react&#39;;</pre><pre>function Form() {<br>  const id = useId();<br>  return (<br>    &lt;&gt;<br>      &lt;label htmlFor={id}&gt;Name:&lt;/label&gt;<br>      &lt;input id={id} /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h3>🚀 Conclusion</h3><p>React hooks make your components simpler, cleaner, and more powerful. Start with useState, useEffect, and useContext, then move to advanced ones like useReducer, useCallback, and useTransition.</p><p>Keep practicing and slowly add hooks into your projects. Happy coding! 💻✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5e2f5a25573" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL with Next.js + WordPress — My Practical Guide]]></title>
            <link>https://medium.com/@insafinhaam732/graphql-with-next-js-wordpress-my-practical-guide-b343c11bc32c?source=rss-31b825cf15ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/b343c11bc32c</guid>
            <dc:creator><![CDATA[Insafinhaam]]></dc:creator>
            <pubDate>Tue, 06 May 2025 18:17:42 GMT</pubDate>
            <atom:updated>2025-06-07T12:32:05.247Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧬 GraphQL with Next.js + WordPress — My Practical Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KZnsr4CJYf_MzPsYOABa-A.png" /></figure><p>Hey everyone! 👋<br>So recently, I started diving deep into building websites using <strong>Next.js</strong> with <strong>WordPress as a headless CMS</strong>, and guess what? I picked <strong>GraphQL</strong> instead of REST — and I’m loving it! 💥</p><p>In this post, I’ll break down:</p><ul><li>What GraphQL is (in simple terms)</li><li>How it works</li><li>Why it’s better than REST for modern web projects</li><li>How I use GraphQL with <strong>Next.js</strong> and <strong>WordPress</strong></li><li>Some cool tools, videos, and AI-generated images to help along the way</li></ul><h3>🌐 What is GraphQL (for real)?</h3><p>Imagine instead of calling a REST API and getting a bunch of extra data you don’t need, you could just <strong>ask for exactly what you want</strong>. That’s GraphQL.</p><p>It was developed by Facebook, and it’s open-source. Instead of having multiple REST endpoints, there’s <strong>only one endpoint</strong>, and you send queries like this:</p><pre>query {<br>  posts {<br>    nodes {<br>      title<br>      featuredImage {<br>        node {<br>          sourceUrl<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>So clean, right?</p><h3>🧠 How GraphQL Works (Simple Explanation)</h3><p>Here’s the basic idea:</p><ol><li><strong>Schema</strong> — defines what data you can request (like a contract).</li><li><strong>Queries</strong> — you write these to fetch the data.</li><li><strong>Resolvers</strong> — these are behind-the-scenes functions that fetch the actual data.</li><li><strong>Mutations</strong> — for changing or creating data (e.g., submitting a form).</li></ol><blockquote><em>GraphQL is like talking to a waiter:</em></blockquote><ul><li>You order (query)</li><li>The kitchen (resolvers) prepares it</li><li>You get only what you asked for — not the whole menu!</li></ul><h3>⚡ Using GraphQL with WordPress (via WPGraphQL)</h3><p>Now here comes the real juice 🍹</p><p>WordPress doesn’t support GraphQL out of the box. So we install this awesome plugin:</p><p>👉 <a href="https://www.wpgraphql.com/">WPGraphQL Plugin</a></p><p>Once installed, you’ll get access to an /graphql endpoint. That’s it!</p><p>You can now query all your WordPress data (posts, pages, media, menus, custom post types, ACF fields, etc.) using GraphQL.</p><blockquote><em>✅ Pro tip: Also install </em><a href="https://wordpress.org/plugins/wp-graphiql/"><em>WPGraphiQL</em></a><em> — a nice GraphQL playground inside your WP dashboard.</em></blockquote><h3>Example query for WordPress posts:</h3><pre>query GetPosts {<br>  posts {<br>    nodes {<br>      title<br>      excerpt<br>      date<br>      uri<br>    }<br>  }<br>}</pre><h3>🛠️ Using GraphQL in Next.js</h3><p>This is where it gets exciting! Let’s build a <strong>React/Next.js</strong> frontend powered by <strong>WordPress</strong> and <strong>GraphQL</strong>.</p><h3>1. Install the GraphQL client</h3><p>I like using <a href="https://github.com/jensneuse/graphql-request">graphql-request</a> because it’s super lightweight:</p><pre>npm install graphql-request</pre><h3>2. Set up a simple fetch function</h3><pre>// lib/graphql-client.ts<br>import { GraphQLClient } from &#39;graphql-request&#39;</pre><pre>const client = new GraphQLClient(&#39;https://your-wp-site.com/graphql&#39;)</pre><pre>export default client</pre><h3>3. Use in your Next.js app</h3><pre>// app/page.tsx or app/blog/page.tsx (if you&#39;re using App Router)<br>import client from &#39;@/lib/graphql-client&#39;<br>import { gql } from &#39;graphql-request&#39;</pre><pre>export default async function BlogPage() {<br>  const query = gql`<br>    query GetPosts {<br>      posts {<br>        nodes {<br>          title<br>          uri<br>        }<br>      }<br>    }<br>  `<br>  const data = await client.request(query)<br>  const posts = data.posts.nodes</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Latest Posts&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {posts.map((post: any) =&gt; (<br>          &lt;li key={post.uri}&gt;{post.title}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>🔗 Handy Links</h3><ul><li>WPGraphQL docs: <a href="https://www.wpgraphql.com/docs/">wpgraphql.com/docs</a></li><li>GraphQL playground: <a href="https://graphql.org/swapi-graphql">graphql.org/swapi-graphql</a></li><li>Next.js docs: <a href="https://nextjs.org/docs">nextjs.org/docs</a></li><li>GraphQL Code Generator (optional): <a href="https://the-guild.dev/graphql/codegen">GraphQL Codegen</a></li></ul><h3>📦 Real World Use Cases (why I love it)</h3><ul><li>Super fast data fetching — no over-fetching</li><li>Reusable queries/components</li><li>Clean frontend logic</li><li>Works great with SSR or static sites in Next.js</li><li>Easy to scale when the site grows</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b343c11bc32c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>