<?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 Mehek Abhyankar on Medium]]></title>
        <description><![CDATA[Stories by Mehek Abhyankar on Medium]]></description>
        <link>https://medium.com/@mehek.a?source=rss-bf10136348ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MZFMiO6YwPBjCIw2</url>
            <title>Stories by Mehek Abhyankar on Medium</title>
            <link>https://medium.com/@mehek.a?source=rss-bf10136348ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:02:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mehek.a/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[Building a Mood-Based Music Player in React Native]]></title>
            <link>https://medium.com/@mehek.a/building-a-mood-based-music-player-in-react-native-edf77c1e56c7?source=rss-bf10136348ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/edf77c1e56c7</guid>
            <category><![CDATA[audio-mananagment]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[dynamic-theme]]></category>
            <category><![CDATA[handling-events]]></category>
            <category><![CDATA[mood-music]]></category>
            <dc:creator><![CDATA[Mehek Abhyankar]]></dc:creator>
            <pubDate>Mon, 20 Apr 2026 02:53:43 GMT</pubDate>
            <atom:updated>2026-04-20T02:53:43.214Z</atom:updated>
            <content:encoded><![CDATA[<p>Every music app ever built asks you the same thing: what do you want to listen to? You search, you scroll, you pick. It works fine. But there is something slightly off about it — music is one of the most emotional things we interact with, and the interface for it is basically a spreadsheet.</p><p>What if the app asked how you were feeling instead?</p><p>That question is what MoodTunes is built around. It is a React Native music player where you pick a mood — Happy, Sad, or Chill — and the app gives you a playlist for that mood. That part is not new. The part that is slightly more interesting is that the entire UI changes color with the mood. The background, the buttons, the card, the accent colors — everything shifts. The app does not just play different music, it feels different.</p><p>This post walks through how to build it, and more importantly, why the code is structured the way it is.</p><h3>What You Need</h3><p>Just a browser. The whole thing runs on Expo Snack at snack.expo.dev — no local setup, no dependency installs. Open it, paste the code, hit run. expo-av comes pre-installed.</p><h3>The One Decision That Shapes Everything</h3><p>Before writing a single line of component code, there is one structural decision worth thinking about: where does mood live, and what does it control?</p><p>The tempting approach is to have separate state for the current theme colors, the current playlist, and the current mood label. Three pieces of state, three places to update when the user switches mood. That gets messy quickly.</p><p>The cleaner approach — and the one MoodTunes uses — is to treat mood as the single source of truth and derive everything else from it. One state variable, mood, and two objects that map mood to its data:</p><pre>const MOODS = {<br>  happy: {<br>    label: &quot;Happy&quot;,<br>    bg: &quot;#FFF8E7&quot;,<br>    primary: &quot;#F4A623&quot;,<br>    card: &quot;#FFF0CC&quot;,<br>  },<br>  sad: {<br>    label: &quot;Sad&quot;,<br>    bg: &quot;#EEF2FF&quot;,<br>    primary: &quot;#5B7FFF&quot;,<br>    card: &quot;#DDE5FF&quot;,<br>  },<br>  chill: {<br>    label: &quot;Chill&quot;,<br>    bg: &quot;#EDFDF8&quot;,<br>    primary: &quot;#2EC4A9&quot;,<br>    card: &quot;#C8F5EC&quot;,<br>  },<br>};<br><br>const SONGS = {<br>  happy: [<br>    { name: &quot;Summer Bounce&quot;,  artist: &quot;BrightWave&quot;, uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3&quot; },<br>    { name: &quot;Feel Good&quot;,      artist: &quot;SunnySide&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3&quot; },<br>  ],<br>  sad: [<br>    { name: &quot;Rainy Window&quot;,   artist: &quot;MeloDrift&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-7.mp3&quot; },<br>    { name: &quot;Missing You&quot;,    artist: &quot;SoftEcho&quot;,   uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3&quot; },<br>  ],<br>  chill: [<br>    { name: &quot;Ocean Breeze&quot;,   artist: &quot;LoFiLab&quot;,    uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3&quot; },<br>    { name: &quot;Lazy Afternoon&quot;, artist: &quot;ChillMood&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3&quot; },<br>  ],<br>};</pre><p>Now the function that handles a mood change is two lines:</p><pre>const changeMood = (newMood) =&gt; {<br>  setMood(newMood);<br>  setIndex(0);<br>};</pre><p>Set the mood, reset the song index to zero. Everything else in the UI reads from mood and updates automatically. Adding a fourth mood later means adding one entry to MOODS and one array to SONGS — nothing else changes.</p><p>That kind of extensibility is worth designing for upfront.</p><h3>How the App Flows</h3><p>Before getting into code, here is the basic flow of the app from the user’s perspective:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*XOMuRbo3hIDMv9Jvx8LQLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*FbFusvk4ca1_Zvac5TRLPg.png" /></figure><p>Every step after choosing a mood is driven by two pieces of state — index for which song is playing, and mood for which playlist and theme is active. That is the whole app.</p><h3>Getting Audio to Work</h3><p>React Native does not play audio natively out of the box. You need expo-av, which gives you an Audio.Sound object you can create, play, pause, and unload.</p><p>The loading logic lives inside a useEffect that watches two dependencies — mood and index. Whenever either changes, it loads the new song:</p><pre>useEffect(() =&gt; {<br>  loadSong();<br>  return () =&gt; {<br>    if (sound) sound.unloadAsync();<br>  };<br>}, [mood, index]);<br><br>const loadSong = async () =&gt; {<br>  if (sound) await sound.unloadAsync();<br><br>  const { sound: newSound } = await Audio.Sound.createAsync(<br>    { uri: songs[index].uri }<br>  );<br><br>  setSound(newSound);<br>  setIsPlaying(false);<br>};</pre><p>The return inside the useEffect is the cleanup function. It runs before the effect fires again, which means before every new song load, the previous sound object gets unloaded from memory. Skip this and you end up with multiple audio streams competing with each other — not a fun bug to track down.</p><p>Play and pause are straightforward:</p><pre>const playPause = async () =&gt; {<br>  if (!sound) return;<br><br>  if (isPlaying) {<br>    await sound.pauseAsync();<br>    setIsPlaying(false);<br>  } else {<br>    await sound.playAsync();<br>    setIsPlaying(true);<br>  }<br>};</pre><p>And navigating between songs uses modulo to wrap the index:</p><pre>const nextSong = () =&gt; setIndex((prev) =&gt; (prev + 1) % songs.length);<br>const prevSong = () =&gt; setIndex((prev) =&gt; (prev - 1 + songs.length) % songs.length);</pre><p>What this means in plain terms: if you are on the last song and press Next, it loops back to the first. If you are on the first song and press Previous, it jumps to the last. The + songs.length in prevSong is there because without it, going below zero gives you a negative index, which would break things.</p><h3>The Theming Part</h3><p>This is the part that makes the app feel like a real product rather than a homework exercise.</p><p>At the top of the render, we pull out the current theme based on the active mood:</p><pre>const theme = MOODS[mood];</pre><p>Then we pass its colors directly into our styles:</p><pre>&lt;View style={[styles.root, { backgroundColor: theme.bg }]}&gt;<br><br>&lt;View style={[styles.card, { backgroundColor: theme.card }]}&gt;<br><br>&lt;TouchableOpacity style={[styles.playBtn, { backgroundColor: theme.primary }]}&gt;</pre><p>React Native lets you pass an array into the style prop. The first item is the base style from StyleSheet, and the second is an object that overrides specific properties — in this case, the background color. So the layout stays fixed and only the colors swap out.</p><p>The mood selector buttons work the same way. The active mood pill fills with the primary color, the inactive ones sit back in the lighter shade:</p><pre>{Object.entries(MOODS).map(([key, val]) =&gt; (<br>  &lt;TouchableOpacity<br>    key={key}<br>    onPress={() =&gt; changeMood(key)}<br>    style={[<br>      styles.moodPill,<br>      { backgroundColor: mood === key ? val.primary : val.card },<br>    ]}<br>  &gt;<br>    &lt;Text style={{ color: mood === key ? &quot;#fff&quot; : val.primary }}&gt;<br>      {val.label}<br>    &lt;/Text&gt;<br>  &lt;/TouchableOpacity&gt;<br>))}</pre><p>mood === key is just checking whether the button being rendered is the currently active mood. If yes, fill it. If not, keep it light. No extra variables needed.</p><h3>Full Source Code</h3><pre>import React, { useState, useEffect } from &quot;react&quot;;<br>import {<br>  View,<br>  Text,<br>  StyleSheet,<br>  TouchableOpacity,<br>  StatusBar,<br>} from &quot;react-native&quot;;<br>import { Audio } from &quot;expo-av&quot;;<br><br>const MOODS = {<br>  happy: {<br>   <br>    label: &quot;Happy&quot;,<br>    bg: &quot;#FFF8E7&quot;,<br>    primary: &quot;#F4A623&quot;,<br>    card: &quot;#FFF0CC&quot;,<br>  },<br>  sad: {<br>   <br>    label: &quot;Sad&quot;,<br>    bg: &quot;#EEF2FF&quot;,<br>    primary: &quot;#5B7FFF&quot;,<br>    card: &quot;#DDE5FF&quot;,<br>  },<br>  chill: {<br>    <br>    label: &quot;Chill&quot;,<br>    bg: &quot;#EDFDF8&quot;,<br>    primary: &quot;#2EC4A9&quot;,<br>    card: &quot;#C8F5EC&quot;,<br>  },<br>};<br><br>const SONGS = {<br>  happy: [<br>    { name: &quot;Summer Bounce&quot;,  artist: &quot;BrightWave&quot;, uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3&quot; },<br>    { name: &quot;Feel Good&quot;,      artist: &quot;SunnySide&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3&quot; },<br>  ],<br>  sad: [<br>    { name: &quot;Rainy Window&quot;,   artist: &quot;MeloDrift&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-7.mp3&quot; },<br>    { name: &quot;Missing You&quot;,    artist: &quot;SoftEcho&quot;,   uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3&quot; },<br>  ],<br>  chill: [<br>    { name: &quot;Ocean Breeze&quot;,   artist: &quot;LoFiLab&quot;,    uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3&quot; },<br>    { name: &quot;Lazy Afternoon&quot;, artist: &quot;ChillMood&quot;,  uri: &quot;https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3&quot; },<br>  ],<br>};<br><br>export default function App() {<br>  const [mood,      setMood]      = useState(&quot;happy&quot;);<br>  const [sound,     setSound]     = useState(null);<br>  const [isPlaying, setIsPlaying] = useState(false);<br>  const [index,     setIndex]     = useState(0);<br><br>  const songs   = SONGS[mood];<br>  const theme   = MOODS[mood];<br>  const current = songs[index];<br><br>  useEffect(() =&gt; {<br>    loadSong();<br>    return () =&gt; { if (sound) sound.unloadAsync(); };<br>  }, [mood, index]);<br><br>  const loadSong = async () =&gt; {<br>    if (sound) await sound.unloadAsync();<br>    const { sound: newSound } = await Audio.Sound.createAsync({ uri: current.uri });<br>    setSound(newSound);<br>    setIsPlaying(false);<br>  };<br><br>  const playPause = async () =&gt; {<br>    if (!sound) return;<br>    if (isPlaying) {<br>      await sound.pauseAsync();<br>      setIsPlaying(false);<br>    } else {<br>      await sound.playAsync();<br>      setIsPlaying(true);<br>    }<br>  };<br><br>  const nextSong = () =&gt; setIndex((prev) =&gt; (prev + 1) % songs.length);<br>  const prevSong = () =&gt; setIndex((prev) =&gt; (prev - 1 + songs.length) % songs.length);<br><br>  const changeMood = (newMood) =&gt; {<br>    setMood(newMood);<br>    setIndex(0);<br>  };<br><br>  return (<br>    &lt;View style={[styles.root, { backgroundColor: theme.bg }]}&gt;<br>      &lt;StatusBar barStyle=&quot;dark-content&quot; /&gt;<br><br>      &lt;Text style={styles.appTitle}&gt; MoodTunes&lt;/Text&gt;<br><br>      {/* ── MOOD PILLS ── */}<br>      &lt;View style={styles.moodRow}&gt;<br>        {Object.entries(MOODS).map(([key, val]) =&gt; (<br>          &lt;TouchableOpacity<br>            key={key}<br>            onPress={() =&gt; changeMood(key)}<br>            style={[<br>              styles.moodPill,<br>              { backgroundColor: mood === key ? val.primary : val.card },<br>            ]}<br>          &gt;<br>            &lt;Text style={[styles.moodPillText, { color: mood === key ? &quot;#fff&quot; : val.primary }]}&gt;<br>              {val.emoji} {val.label}<br>            &lt;/Text&gt;<br>          &lt;/TouchableOpacity&gt;<br>        ))}<br>      &lt;/View&gt;<br><br>      {/* ── PLAYER CARD ── */}<br>      &lt;View style={[styles.card, { backgroundColor: theme.card }]}&gt;<br><br>        {/* Disc art */}<br>        &lt;View style={[styles.disc, { borderColor: theme.primary }]}&gt;<br>          &lt;View style={[styles.discInner, { backgroundColor: theme.primary }]}&gt;<br>            &lt;Text style={styles.discEmoji}&gt;{theme.emoji}&lt;/Text&gt;<br>          &lt;/View&gt;<br>        &lt;/View&gt;<br><br>        {/* Song info */}<br>        &lt;Text style={styles.songName}&gt;{current.name}&lt;/Text&gt;<br>        &lt;Text style={styles.artistName}&gt;{current.artist}&lt;/Text&gt;<br><br>        {/* Mood tag */}<br>        &lt;View style={[styles.tag, { backgroundColor: theme.primary + &quot;22&quot; }]}&gt;<br>          &lt;Text style={[styles.tagText, { color: theme.primary }]}&gt;<br>            {theme.emoji} {theme.label} Mood<br>          &lt;/Text&gt;<br>        &lt;/View&gt;<br><br>        {/* ── CONTROLS ── */}<br>        &lt;View style={styles.controls}&gt;<br>          &lt;TouchableOpacity onPress={prevSong} style={styles.skipBtn}&gt;<br>            &lt;Text style={[styles.skipIcon, { color: theme.primary }]}&gt;⏮&lt;/Text&gt;<br>          &lt;/TouchableOpacity&gt;<br><br>          &lt;TouchableOpacity<br>            onPress={playPause}<br>            style={[styles.playBtn, { backgroundColor: theme.primary }]}<br>          &gt;<br>            &lt;Text style={styles.playIcon}&gt;{isPlaying ? &quot;⏸&quot; : &quot;▶&quot;}&lt;/Text&gt;<br>          &lt;/TouchableOpacity&gt;<br><br>          &lt;TouchableOpacity onPress={nextSong} style={styles.skipBtn}&gt;<br>            &lt;Text style={[styles.skipIcon, { color: theme.primary }]}&gt;⏭&lt;/Text&gt;<br>          &lt;/TouchableOpacity&gt;<br>        &lt;/View&gt;<br><br>        &lt;Text style={styles.counter}&gt;<br>          {index + 1} / {songs.length} songs in this mood<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>    &lt;/View&gt;<br>  );<br>}<br>const styles = StyleSheet.create({<br>  root:         { flex: 1, alignItems: &quot;center&quot;, paddingTop: 60, paddingHorizontal: 20 },<br>  appTitle:     { fontSize: 26, fontWeight: &quot;800&quot;, marginBottom: 24, color: &quot;#222&quot;, letterSpacing: 0.5 },<br>  moodRow:      { flexDirection: &quot;row&quot;, gap: 10, marginBottom: 30 },<br>  moodPill:     { paddingHorizontal: 16, paddingVertical: 9, borderRadius: 20 },<br>  moodPillText: { fontSize: 13, fontWeight: &quot;700&quot; },<br>  card:         { width: &quot;100%&quot;, borderRadius: 28, padding: 28, alignItems: &quot;center&quot;, elevation: 6 },<br>  disc:         { width: 140, height: 140, borderRadius: 70, borderWidth: 6, alignItems: &quot;center&quot;, justifyContent: &quot;center&quot;, marginBottom: 22, backgroundColor: &quot;#fff&quot; },<br>  discInner:    { width: 70, height: 70, borderRadius: 35, alignItems: &quot;center&quot;, justifyContent: &quot;center&quot; },<br>  discEmoji:    { fontSize: 28 },<br>  songName:     { fontSize: 20, fontWeight: &quot;800&quot;, textAlign: &quot;center&quot;, color: &quot;#222&quot; },<br>  artistName:   { fontSize: 14, marginTop: 4, marginBottom: 12, color: &quot;#777&quot; },<br>  tag:          { paddingHorizontal: 14, paddingVertical: 5, borderRadius: 12, marginBottom: 24 },<br>  tagText:      { fontSize: 12, fontWeight: &quot;700&quot; },<br>  controls:     { flexDirection: &quot;row&quot;, alignItems: &quot;center&quot;, gap: 24, marginBottom: 16 },<br>  skipBtn:      { padding: 8 },<br>  skipIcon:     { fontSize: 26 },<br>  playBtn:      { width: 64, height: 64, borderRadius: 32, alignItems: &quot;center&quot;, justifyContent: &quot;center&quot;, elevation: 5 },<br>  playIcon:     { fontSize: 26, color: &quot;#fff&quot; },<br>  counter:      { fontSize: 12, color: &quot;#aaa&quot; },<br>});</pre><h3><strong>Screenshots</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*0Q4T_J-yONWJP-MAEkPJog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*Bb-G-1ai8zeUW51P1u8GPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*5kvk6CuEHp3uzR2gsbCzRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*TVnuABsuMi4JCM0P2-TfmQ.png" /><figcaption>Happy, Sad, and Chill moods with dynamic music and UI updates.</figcaption></figure><h3>Where to Take It Further</h3><p>The version above is deliberately simple. A few things you could add if you want to keep going:</p><p>A progress bar showing how far into the song you are. expo-av has a method called getStatusAsync that tells you the current position and total duration — that is everything you need to draw a bar and update it as the song plays.</p><p>A spinning animation on the disc while music is playing. React Native has a built-in Animated library that can rotate any element on a loop. It sounds complicated but it is about twenty extra lines.</p><p>Saving your mood history so you can see which moods you have been in most often. React Native has a built-in storage tool called AsyncStorage that works like a simple save file for your app.</p><h3>One Last Thing</h3><p>The most useful thing MoodTunes teaches is something that applies to pretty much any app you build: if you organise your data well at the start, the rest of the code almost writes itself.</p><p>Because mood controls both the colors and the playlist from one place, there is no juggling, no keeping things in sync, no wondering why one part of the screen updated and another did not. You change the mood, everything follows.</p><p>That is a small lesson from a small project, but it is one worth carrying forward.</p><h3>Conclusion</h3><p>MoodTunes demonstrates how a single user input — the selected mood — can drive multiple parts of an application in a structured way. Once the mood is chosen, it controls the playlist, the UI theme, and the overall experience, ensuring that all components stay in sync automatically.</p><p>This approach highlights the importance of designing applications where related data is connected through a central state rather than being managed separately. It reduces complexity in logic flow and makes the application easier to maintain and extend.</p><p>Overall, this project shows how React Native can be used to build interactive, responsive applications where UI and functionality adapt together based on user input, creating a more engaging experience.</p><p><em>Tested on Expo Snack. No setup required beyond a browser.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edf77c1e56c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux vs Context API in React Native — which should you use?]]></title>
            <link>https://medium.com/@mehek.a/redux-vs-context-api-in-react-native-which-should-you-use-8c4afa093889?source=rss-bf10136348ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c4afa093889</guid>
            <category><![CDATA[context-api]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Mehek Abhyankar]]></dc:creator>
            <pubDate>Thu, 02 Apr 2026 11:50:21 GMT</pubDate>
            <atom:updated>2026-04-02T11:50:21.665Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A practical guide with code examples</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*mzwMqHBzZC-MEOYUHhAAow.png" /></figure><p>Every React Native developer hits the same wall: your app grows, components need to share state, and passing props three levels deep starts to feel wrong. At that point, two names come up — Context API and Redux. Both solve the same problem. But they are very different tools.</p><p>In this post, we’ll break down what each one does, when to reach for it, and let the code do the talking.</p><h3>The problem: prop drilling</h3><p>Imagine you have a user object at the top of your app and you need it in a deeply nested component. Without any state management, it looks like this:</p><pre>function App() {<br>  const user = { name: &#39;Mehek&#39;, role: &#39;admin&#39; };<br>  return &lt;Dashboard user={user} /&gt;;<br>}<br><br>function Dashboard({ user }) {<br>  return &lt;Sidebar user={user} /&gt;;  // just passing it down<br>}<br><br>function Sidebar({ user }) {<br>  return &lt;Profile user={user} /&gt;;  // still just passing it down<br>}<br><br>function Profile({ user }) {<br>  return &lt;Text&gt;Hello, {user.name}&lt;/Text&gt;;  // finally used here<br>}</pre><p><strong>Dashboard</strong> and <strong>Sidebar</strong> don’t need user at all — they’re just middlemen. This gets messy fast. Context API and Redux both let Profile access user directly.</p><h3>What is the Context API?</h3><p>Context API is built into React. No installation needed. You create a context, wrap your app in a provider, and any component can read from it directly.</p><h4>Step 1: create the context</h4><pre>import React, { createContext, useContext, useState } from &#39;react&#39;;<br>const UserContext = createContext();</pre><h4>Step 2: create a provider</h4><pre>export function UserProvider({ children }) {<br>  const [user, setUser] = useState({ name: &#39;Mehek&#39;, role: &#39;admin&#39; });<br><br>  return (<br>    &lt;UserContext.Provider value={{ user, setUser }}&gt;<br>      {children}<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}</pre><h4>Step 3: wrap your app</h4><pre>import { UserProvider } from &#39;./UserContext&#39;;<br><br>export default function App() {<br>  return (<br>    &lt;UserProvider&gt;<br>      &lt;Dashboard /&gt;<br>    &lt;/UserProvider&gt;<br>  );<br>}</pre><h4>Step 4: consume in any component</h4><pre>import { useContext } from &#39;react&#39;;<br>import { UserContext } from &#39;./UserContext&#39;;<br><br>function Profile() {<br>  const { user } = useContext(UserContext);<br>  return &lt;Text&gt;Hello, {user.name}&lt;/Text&gt;;<br>}<br><br>// No props needed — Profile reads directly from context!</pre><blockquote><em>Context API is perfect for state that changes infrequently — user info, theme (dark/light mode), language/locale settings.</em></blockquote><h3>What is Redux?</h3><p>Redux is a separate library that gives your app a single global <em>store</em> — one place where all your state lives. Components can read from it and dispatch actions to update it. The flow is always: <strong>action → reducer → new state → UI updates</strong>.</p><h4>Install it first:</h4><pre>npm install redux react-redux</pre><h4>Step 1: write a reducer</h4><p>A reducer is just a function that takes the current state and an action, and returns new state.</p><pre>const initialState = { count: 0 };<br><br>function counterReducer(state = initialState, action) {<br>  switch (action.type) {<br>    case &#39;INCREMENT&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;DECREMENT&#39;:<br>      return { count: state.count - 1 };<br>    case &#39;RESET&#39;:<br>      return { count: 0 };<br>    default:<br>      return state;<br>  }<br>}</pre><h4>Step 2: create the store</h4><pre>import { createStore } from &#39;redux&#39;;<br>import counterReducer from &#39;./counterReducer&#39;;<br><br>const store = createStore(counterReducer);</pre><h4>Step 3: provide the store to your app</h4><pre>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./store&#39;;<br><br>export default function App() {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;Counter /&gt;<br>    &lt;/Provider&gt;<br>  );<br>}</pre><h4>Step 4: read and update from a component</h4><pre>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br><br>function Counter() {<br>  const count = useSelector((state) =&gt; state.count);<br>  const dispatch = useDispatch();<br><br>  return (<br>    &lt;&gt;<br>      &lt;Text&gt;Count: {count}&lt;/Text&gt;<br>      &lt;Button title=&quot;+&quot; onPress={() =&gt; dispatch({ type: &#39;INCREMENT&#39; })} /&gt;<br>      &lt;Button title=&quot;-&quot; onPress={() =&gt; dispatch({ type: &#39;DECREMENT&#39; })} /&gt;<br>      &lt;Button title=&quot;Reset&quot; onPress={() =&gt; dispatch({ type: &#39;RESET&#39; })} /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><blockquote><strong><em>useSelector</em></strong><em> reads state from the store. </em><strong><em>useDispatch</em></strong><em> gives you a function to send actions. These two hooks are all you need in most components.</em></blockquote><h3>Side-by-side comparison</h3><pre>Feature              Context API       Redux<br>─────────────────────────────────────────────────<br>Installation         Built-in          npm install needed<br>Boilerplate          Minimal           More (actions, reducers)<br>DevTools             No                Yes (Redux DevTools)<br>Best for             Simple/medium     Large, complex apps<br>Middleware support   No                Yes</pre><h3>When to use Context API</h3><ul><li>You need to share UI state — theme, locale, auth user</li><li>The state doesn’t change very frequently</li><li>You’re building a small-to-medium app</li><li>You want zero dependencies</li></ul><h3>When to use Redux</h3><ul><li>Your app has complex, interconnected state</li><li>Multiple developers are working on the same codebase</li><li>You need to debug state changes step by step (Redux DevTools)</li><li>You need middleware for async flows (API calls, side effects)</li></ul><blockquote><em>Don’t reach for Redux just because your app “might get bigger.” Start with Context, migrate when you actually feel the pain.</em></blockquote><h3>The hybrid approach</h3><p>Many production apps use both.</p><ul><li>Use <strong>Context API</strong> for UI state — theme, logged-in user, language</li><li>Use <strong>Redux</strong> for domain state — cart items, fetched API data, notifications</li></ul><p>This keeps Redux focused on the data that actually needs global management, and Context handles the lighter UI-level stuff.</p><blockquote><em>Context API and Redux both eliminate prop drilling — but they’re built for different scales. If you’re just starting out or building a small app, Context API is all you need. If your app is growing fast with lots of interconnected state, Redux gives you the structure to keep things manageable. Neither is wrong. The best choice is the one that matches where your app actually is today.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c4afa093889" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>