<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aniket Raikwar</title>
    <description>The latest articles on DEV Community by Aniket Raikwar (@aniket_raikwar).</description>
    <link>https://dev.to/aniket_raikwar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F736696%2F7f6e3be4-a470-475a-b80b-2b15231fd39a.png</url>
      <title>DEV Community: Aniket Raikwar</title>
      <link>https://dev.to/aniket_raikwar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aniket_raikwar"/>
    <language>en</language>
    <item>
      <title>Webpack: The Web Module Bundler</title>
      <dc:creator>Aniket Raikwar</dc:creator>
      <pubDate>Sat, 02 Mar 2024 10:20:05 +0000</pubDate>
      <link>https://dev.to/aniket_raikwar/webpack-the-web-module-bundler-1nad</link>
      <guid>https://dev.to/aniket_raikwar/webpack-the-web-module-bundler-1nad</guid>
      <description>&lt;h2&gt;
  
  
  Introduction :
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt; is a tool that helps us to &lt;strong&gt;&lt;em&gt;organize&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;bundle&lt;/em&gt;&lt;/strong&gt; all our website's files (like JavaScript, CSS, images, etc.) into &lt;strong&gt;one&lt;/strong&gt; or a few files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In simpler terms, Webpack is like a magic box that 
takes all our web development ingredients 
(.hbs, .cjs .html, .css, .js, .png, .jpg, etc) 
and turns them into a delicious cake 🍰
that browsers can easily consume.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt; is just allowed us to modularize our code as much as we want the way we like it to be, and finally webpack allows us to just push all of the code into one single file and that file is going to do everything. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;We don't have to worry about the things like:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When should we load this module first, second or third?&lt;/li&gt;
&lt;li&gt;Import and export statement of writing in modern JS and Common JS.&lt;/li&gt;
&lt;li&gt;How SASS can be compile?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt; take care of everything for us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Guide:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
We need to install &lt;a href="https://nodejs.org/en"&gt;&lt;strong&gt;Node.js&lt;/strong&gt;&lt;/a&gt;, which includes &lt;strong&gt;npm&lt;/strong&gt; (Node Package Manager). &lt;br&gt;
Download &amp;amp; Install it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 2:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
If we have to used &lt;strong&gt;Webpack&lt;/strong&gt; from scratch then just create one folder and open it into a code editor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 3:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Open &lt;strong&gt;Terminal&lt;/strong&gt;, and run the below command, for creating the &lt;strong&gt;&lt;em&gt;package.json&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 4:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Now, we need to install two packages that is &lt;a href="https://www.npmjs.com/package/webpack"&gt;&lt;strong&gt;webpack&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/webpack-cli"&gt;&lt;strong&gt;webpack-cli&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
In Terminal, run the below command for installing this packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install webpack webpack-cli --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 5:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
After Installing, create one file with a name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file is responsible for running the &lt;strong&gt;webpack services&lt;/strong&gt;, and we can modified it according to our needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");

module.exports = {
  entry: "./src/index.js",
  module: {
    rules: [
      {
        test: "/.css$/i",
        use: ["style-loader", "css-loader"],
      },
      {
        test: "/.(js)$/",
        use: "babel-loader",
      },
    ],
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
  },
  plugins: [new HtmlWebpackPlugin()],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's try to understand the &lt;strong&gt;code&lt;/strong&gt; line by line which we have wrote in above file 👆.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;1. entry: "index.js"&lt;/strong&gt;&lt;/u&gt; :&lt;br&gt;
This means, &lt;code&gt;"index.js"&lt;/code&gt; is a entry point and it serve as a container for all the javascript code written across the application. &lt;br&gt;
&lt;strong&gt;&lt;em&gt;For Example&lt;/em&gt;&lt;/strong&gt;: In React, &lt;code&gt;"index.js"&lt;/code&gt; file is the root file means it a parent component which contain all the child components.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;2. module (rules)&lt;/strong&gt;&lt;/u&gt; :&lt;br&gt;
Module can set the rules, this means In our application we can used different &lt;strong&gt;packages&lt;/strong&gt; and &lt;strong&gt;libraries&lt;/strong&gt; which is not belonging our browser, now we need to make sure that each and everything which we wrote in our code, browser can be understood easily, so loader played the main role for finding the things and applying the specific loader on it.&lt;/p&gt;

&lt;p&gt;Here, we are using &lt;code&gt;"style-loader"&lt;/code&gt; and &lt;code&gt;"css-loader"&lt;/code&gt;, so whenever &lt;strong&gt;webpack&lt;/strong&gt; find any &lt;strong&gt;css file&lt;/strong&gt;, it applied this two loader one by one on it to process the styling part for the browser.&lt;/p&gt;

&lt;p&gt;Now, not all browser support the &lt;strong&gt;Modern JS&lt;/strong&gt;, so we can used &lt;code&gt;"babel-loader"&lt;/code&gt;, it just find the JS file and convert all the modern syntax code into &lt;code&gt;common js&lt;/code&gt; code syntax, so any browser can easily grab and support the JS code.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;3. output&lt;/strong&gt;&lt;/u&gt; :&lt;br&gt;
Okay, whatever the processed we did till now, we need to show them, otherwise it all waste. So, &lt;strong&gt;webpack&lt;/strong&gt; just create a &lt;code&gt;"dist"&lt;/code&gt; folder and inside that also create &lt;code&gt;"bundle.js"&lt;/code&gt; file which contain all the JS code of the application but in &lt;code&gt;common-js&lt;/code&gt; format.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;4. plugins&lt;/strong&gt;&lt;/u&gt; :&lt;br&gt;
We used &lt;strong&gt;HtmlWebpackPlugin&lt;/strong&gt;, this simply create a new html file &lt;code&gt;"index.html"&lt;/code&gt; inside the &lt;code&gt;"dist"&lt;/code&gt; folder and also integrate the &lt;code&gt;"bundle.js"&lt;/code&gt; file in it. So, this html file is responsible for rendering all the code and showing the result on the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 6:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Now, Once &lt;em&gt;webpack configuration&lt;/em&gt; is done, we need to make a little changes in &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt; file.&lt;br&gt;
Here, inside the &lt;code&gt;"scripts"&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "build": "webpack",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just add this build line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 7:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Now, whenever we run &lt;strong&gt;&lt;code&gt;"npm run build"&lt;/code&gt;&lt;/strong&gt; command in a terminal what actually happened behind the scenes is: &lt;br&gt;
&lt;strong&gt;NodeJs&lt;/strong&gt; will run the &lt;code&gt;"webpack"&lt;/code&gt; command which is &lt;code&gt;"webpack-cli"&lt;/code&gt;, and now it will find the webpack configuration file and execute all the code line by line, &lt;br&gt;
So, it got the &lt;code&gt;"index.js"&lt;/code&gt; file first and trying to execute them, then if they find any &lt;code&gt;"css"&lt;/code&gt; file it try to run the loader to make it available for browser then is there any &lt;code&gt;"modern JS"&lt;/code&gt; code, then run the &lt;code&gt;"babel-loader"&lt;/code&gt; so it will convert code into &lt;code&gt;"common js"&lt;/code&gt; and after all it just create &lt;code&gt;"dist"&lt;/code&gt; folder for the final result 🤗.&lt;/p&gt;

&lt;p&gt;Thats all about &lt;strong&gt;Webpack Basic&lt;/strong&gt;, there are lots of feature of webpack, You can check here: &lt;a href="https://webpack.js.org/"&gt;https://webpack.js.org/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Zustand - The State Management Library for React &amp; Next JS</title>
      <dc:creator>Aniket Raikwar</dc:creator>
      <pubDate>Sat, 13 Jan 2024 11:09:32 +0000</pubDate>
      <link>https://dev.to/aniket_raikwar/zustand-the-state-management-tool-for-react-next-js-p6o</link>
      <guid>https://dev.to/aniket_raikwar/zustand-the-state-management-tool-for-react-next-js-p6o</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;State Management is a crucial aspect of building robust and scalable &lt;strong&gt;React&lt;/strong&gt; &amp;amp; &lt;strong&gt;NextJS&lt;/strong&gt; application. As the Project grow in complexity then handling the state effectively becomes more challenging for developers. That's why the Developer has find one solution for managing all the state globally. There are some library such as &lt;strong&gt;Redux&lt;/strong&gt; and &lt;strong&gt;Redux Toolkit&lt;/strong&gt; but it is more complicated for beginner to understanding the concept of Redux and they really don't know how it’s actually going to work under the hood. &lt;/p&gt;

&lt;p&gt;In this blog, we'll explore &lt;strong&gt;&lt;em&gt;Zustand&lt;/em&gt;&lt;/strong&gt;, a lightweight and efficient state management tool designed for React and NextJS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is State in React?
&lt;/h2&gt;

&lt;p&gt;In React, the state is treated as a variable for example in JavaScript for storing and updating the data we need variables like &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;, it exactly same for React but we called it State. But in deep-down the State refers to an object that represent the data values. &lt;/p&gt;

&lt;h5&gt;
  
  
  Why we not used &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; in React for managing and updating the data?
&lt;/h5&gt;

&lt;p&gt;Because React has a concept of VDOM (Virtual Document Object Model) and whenever the variable like &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; is updated, still React is not responsible for re-render the application and this is default behaviour of React. Re-rendering only happens when the State value is updated or changed. That’s why we used State instead of this JavaScript variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Initialize State in React
&lt;/h2&gt;

&lt;p&gt;We can initialize state in a component using the &lt;code&gt;useState&lt;/code&gt; hook in functional components or by using the state property in class components. Here's a basic example using functional components and the useState hook:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wwwjnwg02pqyysq2qgb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wwwjnwg02pqyysq2qgb.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Here, In the above example the &lt;code&gt;count&lt;/code&gt; variable is part of the component's state, and it can be updated using the &lt;code&gt;setCount&lt;/code&gt; function. &lt;br&gt;
Remember one thing that &lt;em&gt;state&lt;/em&gt; should be treated as &lt;em&gt;immutable&lt;/em&gt;  in React, meaning you should not modify it directly. Instead, always use the provided functions (like &lt;code&gt;setCount&lt;/code&gt; in the below example) to update the state.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmur5t9vki4b77a25yf23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmur5t9vki4b77a25yf23.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is State Management?
&lt;/h2&gt;

&lt;p&gt;In React, every component has it's own local state and sometime we need to pass that data into another component, If two component has relation of parent-child then we can easily pass that &lt;code&gt;state&lt;/code&gt; data using &lt;code&gt;props&lt;/code&gt;, but if there is no relation between that two component then there is no direct way to pass that data. Below image show the example of data passing using &lt;code&gt;props&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here, I have created one more component that name is &lt;code&gt;OtherComponent.js&lt;/code&gt; which simply display the count.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a5g7o20ao62oy4s538m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a5g7o20ao62oy4s538m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we import the &lt;code&gt;OtherComponent.js&lt;/code&gt; in &lt;code&gt;App.js&lt;/code&gt; and passing the &lt;code&gt;count&lt;/code&gt; data value using &lt;code&gt;props&lt;/code&gt;, So now, &lt;code&gt;OtherComponent.js&lt;/code&gt; will also get access of &lt;code&gt;count&lt;/code&gt; state. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6k3w6gs5l1fp65w29tg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6k3w6gs5l1fp65w29tg3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose, If &lt;code&gt;OtherComponent.js&lt;/code&gt; is not a child component of &lt;code&gt;App.js&lt;/code&gt; and it will used in somewhere in the application, then how can we pass that data into that component? &lt;br&gt;
For that, React comes with the &lt;strong&gt;Global State Management Solution&lt;/strong&gt;. In this case, some state has been created in global level, so any component can easily get the have access to that state, and whenever the state is changed or update, it will directly re-render that page where state is used. Below image show How the State is actually manage in global level.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99ms6sdga094nroshtjx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99ms6sdga094nroshtjx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Options for Managing State
&lt;/h2&gt;

&lt;p&gt;In React there are so many option to manage the State in Global Level. If the application is smaller then React has their own feature to provide the state management and that is a &lt;a href="https://react.dev/reference/react/useContext" rel="noopener noreferrer"&gt;Context API&lt;/a&gt; (useContext Hook).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://redux-toolkit.js.org/" rel="noopener noreferrer"&gt;Redux Toolkit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zustand-demo.pmnd.rs/" rel="noopener noreferrer"&gt;Zustand&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://recoiljs.org/" rel="noopener noreferrer"&gt;Recoil&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Understanding Zustand
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/pmndrs/zustand" rel="noopener noreferrer"&gt;Zustand&lt;/a&gt;&lt;/strong&gt; is a small, fast, and scalable state management library that leverages hooks for managing global state. It is very easy to use and not that much complicated, so beginner also comfortable while using &lt;strong&gt;Zustand&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Let's try to implement Zustand with me 😎: *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First install zustand in our project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;npm install zustand&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&gt;

&lt;p&gt;then we need to create one file &lt;code&gt;countStore.js&lt;/code&gt; where our state and their method will be initialize.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbqqmy4smk7szcbw7l7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbqqmy4smk7szcbw7l7m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Zustand&lt;/strong&gt; provide the &lt;code&gt;create&lt;/code&gt; function for creating the store and that store can be used as a &lt;strong&gt;custom hook&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In this example, the &lt;code&gt;useCountStore hook&lt;/code&gt; is used to create a global state with a &lt;code&gt;count&lt;/code&gt; variable and corresponding &lt;code&gt;increment&lt;/code&gt; and &lt;code&gt;decrement&lt;/code&gt; actions.&lt;/p&gt;

&lt;p&gt;Now, this &lt;em&gt;count&lt;/em&gt; state and their &lt;em&gt;actions&lt;/em&gt; can be used in any component throughout the whole application.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulg13c2k6v4h2vt2v9ex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulg13c2k6v4h2vt2v9ex.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;OtherComponent.js&lt;/code&gt; We don't need to pass the count state as a props, we can directly get that state using &lt;strong&gt;useCountStore Hook&lt;/strong&gt;. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjoajbt76varvvhcc2ngo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjoajbt76varvvhcc2ngo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, there are several ways to getting the state in our component below are some example:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5ewyh38wfxtc619xc0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp5ewyh38wfxtc619xc0w.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But I will suggest to used the second one and the last one, Because in the first one, we are using destructure approach for importing all the state and their method, so even if they are not used in their respective component, but updated in any other component still React re-render the components where they are imported and initialized and that will cause affect the performance of the application.&lt;/p&gt;

&lt;p&gt;There are lots thing that can be used in advanced level, but we are end our blog here. I hope you will loved it 🥰.&lt;/p&gt;

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