<?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"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[🚀 Frontend Developer with a passion for React, Next.js, and React Native. Building user-centric web and mobile apps for a captivating digital world. Let's conn]]></description><link>https://blogs.prathameshk.com</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 16:48:14 GMT</lastBuildDate><atom:link href="https://blogs.prathameshk.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Zustand Decoded: The Art of Simple and Scalable State Management in React]]></title><description><![CDATA[Introduction
State management is a crutial part of any web application, it helps keeping track of information (state) such as user inputs or app data. There are many different options that are available to use when it comes to this topic. One such li...]]></description><link>https://blogs.prathameshk.com/zustand-decoded-the-art-of-simple-and-scalable-state-management-in-react</link><guid isPermaLink="true">https://blogs.prathameshk.com/zustand-decoded-the-art-of-simple-and-scalable-state-management-in-react</guid><category><![CDATA[zustand]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[State Management ]]></category><dc:creator><![CDATA[Prathamesh Karambelkar]]></dc:creator><pubDate>Sun, 14 Jan 2024 03:30:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1705176444324/c7ee8722-7945-46a7-9786-a02e40c9e950.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction">Introduction</h3>
<p>State management is a crutial part of any web application, it helps keeping track of information (state) such as user inputs or app data. There are many different options that are available to use when it comes to this topic. One such library is Zustand.</p>
<p>In today's blog we are going to understand what Zustand is and how it works. This is going to be a series of blogs based on Zustand where we will be starting with simple example and ultimately performing CRUD operations.</p>
<blockquote>
<p>Zustand: where bears, beets, and state management meet! 🐻🍠 Unleashing the wild side of React with a touch of Dwight's beary charm.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705156264658/295a2cbe-4c9a-4d39-8388-4b24c3f11df1.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-understanding-zustand">Understanding Zustand</h3>
<blockquote>
<p>A small, fast and scalable bearbones state-management solution using simplified flux principles. Has a comfy API based on hooks, isn't boilerplatey or opinionated.</p>
</blockquote>
<p>This is the definition on its GitHub repository <a target="_blank" href="https://github.com/pmndrs/zustand">GitHub - pmndrs/zustand: 🐻</a></p>
<p>Just the definition is enough to understand how Zustand works. Here, coding is as important to know as how it actually works behind the scenes.</p>
<blockquote>
<p><em>bearbones - Actually it's called barebones -</em> reduced to the essential elements.</p>
</blockquote>
<p>The first key term in the definition is Flux Principles, but what is Flux?</p>
<blockquote>
<p>Flux is the application architecture that Facebook uses for building client-side web applications.</p>
</blockquote>
<p>The architecture comprises of 4 parts:</p>
<ol>
<li><p>Actions</p>
</li>
<li><p>Dispatchers</p>
</li>
<li><p>Store</p>
</li>
<li><p>Views</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705165565282/b5cf0d02-9e5a-46ed-bb80-49a572dfe2f5.png" alt class="image--center mx-auto" /></p>
<p>To understand how Flux architecture works, let us imagine a simple scenario of Supermarket Checkout System.</p>
<p>Imagine being at a supermarket.</p>
<ul>
<li><p><strong><em>View:</em></strong></p>
<ul>
<li><p>Anything we can see or interact with.</p>
</li>
<li><p>e.g.-&gt;Each product represents view.</p>
</li>
</ul>
</li>
<li><p><strong><em>Actions:</em></strong></p>
<ul>
<li><p>Things you want to do.</p>
</li>
<li><p>e.g.-&gt;Adding a product to shopping cart is like an Action. For example, putting an apple in the cart is similar to dispatching an "ADD_TO_CART" action.</p>
</li>
</ul>
</li>
<li><p><strong><em>Dispatcher:</em></strong></p>
<ul>
<li><p>A traffic controller.</p>
</li>
<li><p>e.g.-&gt;The cashier is the dispatcher. He/she makes sure that each and every item is processed. It processes one item and then takes another, basically managing the flow of actions.</p>
</li>
</ul>
</li>
<li><p><strong><em>Store:</em></strong></p>
<ul>
<li><p>Stores contain the application state and logic.</p>
</li>
<li><p>e.g.-&gt;When we add items to the cart, the store gets updated.</p>
</li>
</ul>
</li>
</ul>
<p>This was a simple overview, below is the detailed view.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705170792837/de64b8af-46e7-41ef-9994-690ec81a7dca.png" alt class="image--center mx-auto" /></p>
<p>Now that you understand what flux principles is, it would be easy to understand the code, let us take one simple example.</p>
<h3 id="heading-implementation">Implementation</h3>
<p>I am using Vite, I have initialized the project using <code>yarn create vite</code></p>
<p>Also while setting up, I have installed Zustand using <code>yarn add zustand</code></p>
<p>Now when you initialize a project using Vite, the default App.tsx file has a counter example, will replace it by using Zustand later.</p>
<p>Cleaned up the code a little, now there are two button with basic onClick function which will increase and decrease the count by 1.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./App.css"</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);
  <span class="hljs-keyword">return</span> (
    &lt;&gt;
      &lt;div className=<span class="hljs-string">"card"</span>&gt;
        &lt;button onClick={<span class="hljs-function">() =&gt;</span> setCount(<span class="hljs-function">(<span class="hljs-params">count</span>) =&gt;</span> count + <span class="hljs-number">1</span>)}&gt;Increase&lt;/button&gt;
        &lt;h1&gt;count is {count}&lt;/h1&gt;
        &lt;button onClick={<span class="hljs-function">() =&gt;</span> setCount(<span class="hljs-function">(<span class="hljs-params">count</span>) =&gt;</span> count - <span class="hljs-number">1</span>)}&gt;Decrease&lt;/button&gt;
      &lt;/div&gt;
    &lt;/&gt;
  );
}
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p>Now, as Zustand is based on flux architecture, let us create a store. Remember Zustand is unopinionated, meaning that you can have folder and code structure as you like, I personally like to keep it different, so will create a folder named store and have a file named useCountStore.ts.</p>
<p>To use Zustand, we first bring in a special function called <code>create</code> by importing it.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { create } <span class="hljs-keyword">from</span> <span class="hljs-string">"zustand"</span>;
</code></pre>
<p>We then use this function by providing a set of instructions (a callback function) that defines our state and the actions to change it. The result is a custom hook, like a bundled package, containing our state and functions neatly organized for use in our application.</p>
<p>As I am using typescript, I defined types for my State and Actions.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">type</span> State = {
  count: <span class="hljs-built_in">number</span>;
};
<span class="hljs-keyword">type</span> Actions = {
  increment: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
  decrement: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
  reset: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
};
</code></pre>
<p>Here is my main code, as you can see, I have defined increment and decrement functions. If you observer carefully there is <code>set</code> parameter provided by zustand within the callback function. It is used to update the state within the store.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> useCountStore = create&lt;State &amp; Actions&gt;(<span class="hljs-function">(<span class="hljs-params">set</span>) =&gt;</span> ({
  count: <span class="hljs-number">0</span>,
  increment: <span class="hljs-function">() =&gt;</span> set(<span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> ({ count: state.count + <span class="hljs-number">1</span> })),
  decrement: <span class="hljs-function">() =&gt;</span> set(<span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> ({ count: state.count - <span class="hljs-number">1</span> })),
  reset: <span class="hljs-function">() =&gt;</span> set({ count: <span class="hljs-number">0</span> }),
}));
</code></pre>
<p>Now this <code>set</code> function takes an argument, it can either be a function or an object:</p>
<ul>
<li><p><strong>Function</strong>: If we pass a function to <code>set</code>, it receives the current state, and we can use that to calculate the new state. You can see the increment and decrement function, in that function we are using current state to increase or decrease the count by 1.</p>
</li>
<li><p><strong>Object:</strong> If we pass an object, it will directly replace the current state with the new object. You can see this with reset function.</p>
</li>
</ul>
<p>Let us now export this function.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { create } <span class="hljs-keyword">from</span> <span class="hljs-string">"zustand"</span>;

<span class="hljs-keyword">type</span> State = {
  count: <span class="hljs-built_in">number</span>;
};

<span class="hljs-keyword">type</span> Actions = {
  increment: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
  decrement: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
  reset: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
};

<span class="hljs-keyword">const</span> useCountStore = create&lt;State &amp; Actions&gt;(<span class="hljs-function">(<span class="hljs-params">set</span>) =&gt;</span> ({
  count: <span class="hljs-number">0</span>,
  increment: <span class="hljs-function">() =&gt;</span> set(<span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> ({ count: state.count + <span class="hljs-number">1</span> })),
  decrement: <span class="hljs-function">() =&gt;</span> set(<span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> ({ count: state.count - <span class="hljs-number">1</span> })),
  reset: <span class="hljs-function">() =&gt;</span> set({ count: <span class="hljs-number">0</span> }),
}));

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> useCountStore;
</code></pre>
<p>Now we can use this hook anywhere. Let us import this hook in App.tsx file. I have modified the code and now replaced useState with our hook.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> <span class="hljs-string">"./App.css"</span>;
<span class="hljs-keyword">import</span> useCountStore <span class="hljs-keyword">from</span> <span class="hljs-string">"./store/useCountStore"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> { count, increment, decrement, reset } = useCountStore();
  <span class="hljs-keyword">return</span> (
    &lt;&gt;
      &lt;div className=<span class="hljs-string">"card"</span>&gt;
        &lt;button onClick={<span class="hljs-function">() =&gt;</span> increment()}&gt;Increase&lt;/button&gt;
        &lt;button onClick={<span class="hljs-function">() =&gt;</span> decrement()}&gt;Decrease&lt;/button&gt;
        &lt;h1&gt;count is {count}&lt;/h1&gt;
        &lt;button onClick={<span class="hljs-function">() =&gt;</span> reset()}&gt;Reset Count&lt;/button&gt;
      &lt;/div&gt;
    &lt;/&gt;
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p>Now if you try to increment or decrement, the value of count will be changed globally and you can get the current value of count using the useCountStore hook anywhere in the project.</p>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>As we conclude this introduction to Zustand with a simple example, get ready for the next blog, where we'll delve into more advanced features.</p>
<p>Any questions or tech thoughts? I'm here and excited to connect. Don't miss the upcoming part; make sure to follow for updates.</p>
]]></content:encoded></item><item><title><![CDATA[Behind the Scenes: Understanding the Inner Workings of Custom Tab Bars with React Navigation]]></title><description><![CDATA[Introduction
The default tab bar in React Navigation is rather basic, and attempting to customize it can lead to a messy outcome. Fortunately, there is a straightforward way to implement custom tabs using the Material Top Tab Bar in React Native with...]]></description><link>https://blogs.prathameshk.com/behind-the-scenes-understanding-the-inner-workings-of-custom-tab-bars-with-react-navigation</link><guid isPermaLink="true">https://blogs.prathameshk.com/behind-the-scenes-understanding-the-inner-workings-of-custom-tab-bars-with-react-navigation</guid><category><![CDATA[React Native]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[react-navigation]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Prathamesh Karambelkar]]></dc:creator><pubDate>Sun, 17 Dec 2023 03:30:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1702756417178/39184112-8d36-4636-98b0-186c811c8d1e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction"><strong>Introduction</strong></h3>
<p>The default tab bar in React Navigation is rather basic, and attempting to customize it can lead to a messy outcome. Fortunately, there is a straightforward way to implement custom tabs using the Material Top Tab Bar in React Native with React Navigation. The setup process is quick and can be completed in just a few minutes. Today in this blog we are going to understand how it works.</p>
<p>I am assuming you did the setup of React Navigation in your project, if not follow the <a target="_blank" href="https://reactnavigation.org/docs/getting-started/">steps to set up React Navigation</a> and <a target="_blank" href="https://reactnavigation.org/docs/hello-react-navigation">create a native stack navigator</a>, it's pretty easy.</p>
<p>To have a tab bar on the top of the screen, that lets us switch between routes by tapping the tabs or swiping horizontally, we have <a target="_blank" href="https://reactnavigation.org/docs/material-top-tab-navigator">Material Tob Tabs Navigator</a> by React Navigation. Please refer <a target="_blank" href="https://reactnavigation.org/docs/material-top-tab-navigator/#installation">docs</a>.</p>
<p>This is how my <code>App.tsx</code> looks. It is always a good idea to create separate files for your stack screens. Once your project grows and there are multiple screens the <code>App.tsx</code> becomes cluttered!</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> {NavigationContainer} <span class="hljs-keyword">from</span> <span class="hljs-string">'@react-navigation/native'</span>;
<span class="hljs-comment">// ...</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>): <span class="hljs-title">React</span>.<span class="hljs-title">JSX</span>.<span class="hljs-title">Element</span> </span>{
  <span class="hljs-keyword">return</span> (
    &lt;NavigationContainer&gt;
      &lt;SafeAreaView style={styles.mainContainer}&gt;
        &lt;Navigation /&gt;
      &lt;/SafeAreaView&gt;
    &lt;/NavigationContainer&gt;
  );
}
</code></pre>
<p><code>Navigation.tsx</code></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> {createNativeStackNavigator} <span class="hljs-keyword">from</span> <span class="hljs-string">'@react-navigation/native-stack'</span>;
<span class="hljs-comment">// ...</span>
<span class="hljs-keyword">const</span> Navigation = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> Stack = createNativeStackNavigator();
  <span class="hljs-keyword">return</span> (
    &lt;Stack.Navigator initialRouteName=<span class="hljs-string">"Home"</span>&gt;
      &lt;Stack.Screen
        options={{headerShown: <span class="hljs-literal">false</span>}}
        name=<span class="hljs-string">"Home"</span>
        component={Homescreen}
      /&gt;
    &lt;/Stack.Navigator&gt;
  );
};
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Navigation;
</code></pre>
<p><code>Homescreen.tsx</code></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> {createMaterialTopTabNavigator} <span class="hljs-keyword">from</span> <span class="hljs-string">'@react-navigation/material-top-tabs'</span>;
<span class="hljs-comment">//...</span>
<span class="hljs-keyword">const</span> Homescreen = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> Tab = createMaterialTopTabNavigator();
  <span class="hljs-keyword">return</span> (
    &lt;Tab.Navigator
      tabBar={<span class="hljs-function"><span class="hljs-params">props</span> =&gt;</span> &lt;CustomTabBar {...props} /&gt;}
      style={styles.tabStyle}&gt;
      &lt;Tab.Screen name=<span class="hljs-string">"Demo1"</span> component={DemoScreen1} /&gt;
      &lt;Tab.Screen name=<span class="hljs-string">"Demo2"</span> component={DemoScreen2} /&gt;
      &lt;Tab.Screen
        options={{title: <span class="hljs-string">'Demo Screen 3'</span>}}
        name=<span class="hljs-string">"Demo3"</span>
        component={DemoScreen3}
      /&gt;
    &lt;/Tab.Navigator&gt;
  );
};
</code></pre>
<p>Here is the custom tabBar function</p>
<p><code>CustomTabBar.tsx</code></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> {Animated, View, TouchableOpacity} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">CustomTabBar</span>(<span class="hljs-params">{state, descriptors, navigation, position}: <span class="hljs-built_in">any</span></span>) </span>{
  <span class="hljs-keyword">return</span> (
    &lt;View style={{flexDirection: <span class="hljs-string">'row'</span>}}&gt;
      {state.routes.map(<span class="hljs-function">(<span class="hljs-params">route, index</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> {options} = descriptors[route.key];
        <span class="hljs-keyword">const</span> label =
          options.tabBarLabel !== <span class="hljs-literal">undefined</span>
            ? options.tabBarLabel
            : options.title !== <span class="hljs-literal">undefined</span>
            ? options.title
            : route.name;

        <span class="hljs-keyword">const</span> isFocused = state.index === index;

        <span class="hljs-keyword">const</span> onPress = <span class="hljs-function">() =&gt;</span> {
          <span class="hljs-keyword">const</span> event = navigation.emit({
            <span class="hljs-keyword">type</span>: <span class="hljs-string">'tabPress'</span>,
            target: route.key,
            canPreventDefault: <span class="hljs-literal">true</span>,
          });

          <span class="hljs-keyword">if</span> (!isFocused &amp;&amp; !event.defaultPrevented) {
            navigation.navigate(route.name, route.params);
          }
        };

        <span class="hljs-keyword">const</span> onLongPress = <span class="hljs-function">() =&gt;</span> {
          navigation.emit({
            <span class="hljs-keyword">type</span>: <span class="hljs-string">'tabLongPress'</span>,
            target: route.key,
          });
        };

        <span class="hljs-keyword">const</span> inputRange = state.routes.map(<span class="hljs-function">(<span class="hljs-params">_, i</span>) =&gt;</span> i);
        <span class="hljs-keyword">const</span> opacity = position.interpolate({
          inputRange,
          outputRange: inputRange.map(<span class="hljs-function"><span class="hljs-params">i</span> =&gt;</span> (i === index ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>)),
        });

        <span class="hljs-keyword">return</span> (
          &lt;TouchableOpacity
            key={route.key}
            accessibilityRole=<span class="hljs-string">"button"</span>
            accessibilityState={isFocused ? {selected: <span class="hljs-literal">true</span>} : {}}
            accessibilityLabel={options.tabBarAccessibilityLabel}
            testID={options.tabBarTestID}
            onPress={onPress}
            onLongPress={onLongPress}
            style={{flex: <span class="hljs-number">1</span>}}&gt;
            &lt;Animated.Text style={{color: <span class="hljs-string">'black'</span>}}&gt;{label}&lt;/Animated.Text&gt;
          &lt;/TouchableOpacity&gt;
        );
      })}
    &lt;/View&gt;
  );
}
</code></pre>
<p>Let us break down the function.</p>
<h3 id="heading-internal-working"><strong>Internal working</strong></h3>
<p>These 4 parameters are important while building a Custom tab component:</p>
<h3 id="heading-state"><code>State</code></h3>
<ul>
<li><p>Imagine this as a <code>snapshot</code> of where you are in your app. It keeps track of which screen you're currently viewing and provides a list of all possible routes.</p>
</li>
<li><p>If you just console.log the state, you will get this object, each time you change a screen the state will get updated.</p>
</li>
<li><p>history -&gt; The <code>history</code> is like a record or list of all the screens you have visited in the past. Not all parts of the app have this history feature—only certain parts, like tabs or drawers, might keep track of where you've been</p>
</li>
<li><p>Index -&gt; Position of the focused screen in the routes array.</p>
</li>
<li><p>routesNames -&gt; Name of the screen defined in the navigator.</p>
</li>
</ul>
<pre><code class="lang-json"><span class="hljs-comment">// console.log(state)  </span>
{
    <span class="hljs-attr">"history"</span>: [
      {
        <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo1-tDHcPmmRmdJs837m1-olK"</span>,
        <span class="hljs-attr">"type"</span>: <span class="hljs-string">"route"</span>
      },
      {
        <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo3--0m-QGhSnWqixDeKdoS7D"</span>,
        <span class="hljs-attr">"type"</span>: <span class="hljs-string">"route"</span>
      }
    ],
    <span class="hljs-attr">"index"</span>: <span class="hljs-number">2</span>,
    <span class="hljs-attr">"key"</span>: <span class="hljs-string">"tab-rsFLKC9b4gow_h2x6QelX"</span>,
    <span class="hljs-attr">"routeNames"</span>: [
      <span class="hljs-string">"Demo1"</span>,
      <span class="hljs-string">"Demo2"</span>,
      <span class="hljs-string">"Demo3"</span>
    ],
    <span class="hljs-attr">"routes"</span>: [
      {
        <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo1-tDHcPmmRmdJs837m1-olK"</span>,
        <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Demo1"</span>,
        <span class="hljs-attr">"params"</span>: undefined
      },
      {
        <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo2-EimNrVsIA-ZXW8mCSSxua"</span>,
        <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Demo2"</span>,
        <span class="hljs-attr">"params"</span>: undefined
      },
      {
        <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo3--0m-QGhSnWqixDeKdoS7D"</span>,
        <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Demo3"</span>,
        <span class="hljs-attr">"params"</span>: undefined
      }
    ],
    <span class="hljs-attr">"stale"</span>: <span class="hljs-literal">false</span>,
    <span class="hljs-attr">"type"</span>: <span class="hljs-string">"tab"</span>
  }
</code></pre>
<h3 id="heading-descriptors"><code>Descriptors</code></h3>
<ul>
<li><p>Think of <code>descriptors</code> as a set of instructions for each route. It tells the app how to handle and display each screen, including any special instructions for the tab bar.</p>
<pre><code class="lang-json">  <span class="hljs-comment">// console.log(descriptors)</span>
  <span class="hljs-string">"Demo3-4vfsJoiMZndxF-MRA2cpj"</span>: {
    <span class="hljs-attr">"navigation"</span>: {
      <span class="hljs-attr">"addListener"</span>: [
        FunctionaddListener
      ],
      <span class="hljs-attr">"isFocused"</span>: [
        FunctionisFocused
      ],
      <span class="hljs-attr">"navigate"</span>: [
        Functionanonymous
      ],
      <span class="hljs-attr">"replace"</span>: [
        Functionanonymous
      ],
  ...and many more
    },
    <span class="hljs-attr">"options"</span>: {
      <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Demo SCreen 3"</span>
    },
    <span class="hljs-attr">"render"</span>: [
      Functionrender
    ],
    <span class="hljs-attr">"route"</span>: {
      <span class="hljs-attr">"key"</span>: <span class="hljs-string">"Demo3-4vfsJoiMZndxF-MRA2cpj"</span>,
      <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Demo3"</span>,
      <span class="hljs-attr">"params"</span>: undefined
    }
  }
</code></pre>
</li>
</ul>
<h3 id="heading-navigation"><code>Navigation</code></h3>
<ul>
<li><p>The <code>navigation</code> prop is like a remote control for moving around in your app. It gives you buttons to go to different screens, go back, and perform other actions related to navigation.</p>
</li>
<li><pre><code class="lang-json">      <span class="hljs-comment">// console.log(navigation)</span>
     {
        <span class="hljs-attr">"addListener"</span>: [
          FunctionaddListener
        ],
        <span class="hljs-attr">"dispatch"</span>: [
          Functiondispatch
        ],
        <span class="hljs-attr">"pop"</span>: [
          Functionanonymous
        ],
        <span class="hljs-attr">"popToTop"</span>: [
          Functionanonymous
        ],
        <span class="hljs-attr">"push"</span>: [
          Functionanonymous
        ],
        <span class="hljs-attr">"replace"</span>: [
          Functionanonymous
        ],
      <span class="hljs-comment">//....and many more</span>
      }
</code></pre>
</li>
</ul>
<h3 id="heading-position"><code>Position</code></h3>
<ul>
<li><p>The position helps in creating cool effects, like making tabs fade in or out based on where you are on the list of screens.</p>
</li>
<li><pre><code class="lang-json">  <span class="hljs-comment">// console.log(position)</span>
  <span class="hljs-number">0.8722222447395325</span>
</code></pre>
</li>
</ul>
<p>Now that we know why each parameter is important, it is easy to understand the code. Let us have a look at <code>onPress</code> function.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> onPress = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> event = navigation.emit({
        <span class="hljs-keyword">type</span>: <span class="hljs-string">'tabPress'</span>,
        target: route.key,
        canPreventDefault: <span class="hljs-literal">true</span>,
        });
        <span class="hljs-keyword">if</span> (!isFocused &amp;&amp; !event.defaultPrevented) {
            navigation.navigate(route.name, route.params);
          }
    };
</code></pre>
<p>The default behavior is what normally happens when you tap a tab: it takes you to the screen connected to that tab. The code checks if anything wants to stop this default action before allowing it to happen.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>In this post, we've explored how a custom tab bar function works in React Navigation, focusing on the Material Top Tab Bar in React Native. By breaking down the essential parameters—<code>state</code>, <code>descriptors</code>, <code>navigation</code>, and <code>position</code>—we've unveiled the function's operation.</p>
<p>If you have any questions or just want to talk about tech in general, feel free to reach out to me. Hopefully, this helps you understand React Navigation better.</p>
]]></content:encoded></item></channel></rss>