<?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: NISHARGA KABIR</title>
    <description>The latest articles on DEV Community by NISHARGA KABIR (@nisharga_kabir).</description>
    <link>https://dev.to/nisharga_kabir</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%2F1665172%2Fae1956c9-996c-4cf4-a0ed-ade4c33132cf.jpg</url>
      <title>DEV Community: NISHARGA KABIR</title>
      <link>https://dev.to/nisharga_kabir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nisharga_kabir"/>
    <language>en</language>
    <item>
      <title>React Native Expo Custom Push Notifications</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Fri, 22 Aug 2025 06:30:42 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/react-native-expo-custom-push-notifications-49hk</link>
      <guid>https://dev.to/nisharga_kabir/react-native-expo-custom-push-notifications-49hk</guid>
      <description>&lt;p&gt;&lt;strong&gt;Step 0 is for backend:&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;const express = require("express");
const { Expo } = require("expo-server-sdk") ;

const app = express();
const PORT = 8000;

const expo = new Expo();

app.use(express.json());

app.get("/", (req, res) =&amp;gt; {
  res.send("Welcome to Expo Notification Backend");
});

app.post("/api/push-notification", async (req, res) =&amp;gt; {
  const { token, title, body, metadata } = req.body;
  if (!Expo.isExpoPushToken(token)) {
    throw new Error("Invalid push token", 400);
  }

  const message = {
    to: token,
    sound: "default",
    title: title,
    body: body,
    data: metadata || {},
  };

  const tickets = await expo.sendPushNotificationsAsync([message]);

  return res.status(200).json(tickets);
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running on http://localhost:${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We basically have to install this package.&lt;/p&gt;

&lt;p&gt;"expo-server-sdk": "^3.15.0",&lt;/p&gt;

&lt;p&gt;And using this we will send the notifications&lt;/p&gt;

&lt;p&gt;expo.sendPushNotificationsAsync([message]);&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Generate Expo ID&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;eas init&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F25x2kaai06l8itfl5ul2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F25x2kaai06l8itfl5ul2.png" alt=" " width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have to do this for our react-native expo project 🙂&lt;br&gt;
When you generate an id you will also see it on the dashboard as well &lt;a href="https://expo.dev/accounts/nisharga" rel="noopener noreferrer"&gt;https://expo.dev/accounts/nisharga&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create A Wrapper&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now on the app.tsx we have to create a wrapper&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;PushNotificationManager&amp;gt;&lt;br&gt;
        &amp;lt;View style={styles.container}&amp;gt;&lt;br&gt;
            &amp;lt;Text&amp;gt;Open up App.tsx to start working on your app!&amp;lt;/Text&amp;gt;&lt;br&gt;
            &amp;lt;StatusBar style="auto" /&amp;gt;&lt;br&gt;
        &amp;lt;/View&amp;gt;&lt;br&gt;
     &amp;lt;/PushNotificationManager&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now its time to create the PushNotificationManager&lt;/p&gt;

&lt;p&gt;Step 3: 3/3 It mean you have to understand 3 things before go next :)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You will get the ID once you run the mobile app project
&lt;img src="https://media2.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%2Fextchrncu9akjithn3up.png" alt=" " width="800" height="74"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.and using the ID you have to hit postman route &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5d4iyr85vf6gyhkvo618.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5d4iyr85vf6gyhkvo618.png" alt=" " width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.It wouldn't work on the emulator. Download Expo app on your phone and try this.&lt;/p&gt;

&lt;p&gt;Step 4: Finally full code PushNotificationManager.tsx&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import React, { useEffect, PropsWithChildren } from 'react';
import { Platform } from 'react-native';
import * as Device from 'expo-device';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';

Notifications.setNotificationHandler({
  handleNotification: async () =&amp;gt; ({
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: false,
  }),
});

const PushNotificationManager: React.FC&amp;lt;PropsWithChildren&amp;lt;{}&amp;gt;&amp;gt; = ({
  children,
}) =&amp;gt; {

  const registerForPushNotificationsAsync = async (): Promise&amp;lt;
    string | undefined
  &amp;gt; =&amp;gt; {
    let token;

    if (Platform.OS === 'android') {
      await Notifications.setNotificationChannelAsync('default', {
        name: 'default',
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: '#FF231F7C',
      });
    }

    if (Device.isDevice) {
      const { status: existingStatus } =
        await Notifications.getPermissionsAsync();
      let finalStatus = existingStatus;

      if (existingStatus !== 'granted') {
        const { status } = await Notifications.requestPermissionsAsync();
        finalStatus = status;
      }

      if (finalStatus !== 'granted') {
        console.warn('Failed to get push token for push notification!');
        return;
      }

      // Get Expo Push Token
      try {
        const projectId = Constants.expoConfig?.extra?.eas?.projectId;

        if (!projectId) {
          console.error('No project ID found. Please configure in app.json');
          return;
        }
        token = (
          await Notifications.getExpoPushTokenAsync({
            projectId: projectId,
          })
        ).data;
        console.log('Push Token:', token);
        return token
      } catch (error) {
        console.error('Detailed Error getting push token:', error);

        if (error instanceof Error) {
          console.error('Error name:', error.name);
          console.error('Error message:', error.message);
          console.error('Error stack:', error.stack);
        }
      }
    } else {
      console.warn('Must use physical device for Push Notifications');
    }
    return token;  
};
  useEffect(() =&amp;gt; {
    registerForPushNotificationsAsync().then((token) =&amp;gt; {
      if (token) { }
    });

// Notification received listener
    const receivedSubscription = Notifications.addNotificationReceivedListener(
      (notification) =&amp;gt; {
        console.log(
          'Notification Received:',
          notification.request.content.data,
        );
      },
    );

    // Notification tap listener
    const responseSubscription =
      Notifications.addNotificationResponseReceivedListener((response) =&amp;gt; {
        const data = response.notification.request.content.data;
        console.log('Notification Tapped:', data);
      });

    return () =&amp;gt; {
      receivedSubscription.remove();
      responseSubscription.remove();
    };
  }, []);
  return &amp;lt;&amp;gt;{children}&amp;lt;/&amp;gt;;
};

export default PushNotificationManager;`



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Redux-Toolkit CRUD QUICK OVERVIEW</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Thu, 22 Aug 2024 19:18:08 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/redux-toolkit-crud-quick-overview-mam</link>
      <guid>https://dev.to/nisharga_kabir/redux-toolkit-crud-quick-overview-mam</guid>
      <description>&lt;p&gt;Here, I am giving you a quick overview of Redux Toolkit use cases and performing a CRUD operation. I tried to keep it as brief as possible✅&lt;/p&gt;

&lt;p&gt;I will start directly here. I’ve skipped the Redux Toolkit setup as well. I suggest that after reading this, you follow a playlist or take a crash course to learn, and also refer to the documentation for further learning. Let’s start the game! 😍😍😍&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UnderStand concept&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Redux Toolkit or Redux, you may see two things:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Endpoint Type&lt;br&gt;
  2.Tags&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Two endpoint types are in the redux toolkit. One is a query, and the other is a mutation. In Redux.... getAll or singleGet is called a query; without this, everything else is called a mutation.&lt;/p&gt;

&lt;p&gt;You have to pass a tag inside every API route invalidatesTags or providesTags. &lt;br&gt;
For queries, we use providesTags, which acts like an ID that we set for later use. For mutations, we use invalidatesTags, which simply call back the provided tag. &lt;br&gt;
This means that after completing an /update, /delete, or /post route, the /get or /getAll route is automatically fetched, so we don’t need to refresh to see the updated data. ✅&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 0: Boilerplate create&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;inside feature folder, i create &lt;strong&gt;driverSalaryApi.ts&lt;/strong&gt; You can create as your wish 🙂&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { baseApi } from "../baseApi";

const driverSalaryApi = baseApi.injectEndpoints({
  endpoints: (build) =&amp;gt; ({
    // ALL CODE WILL WRITE HERE
  }),
});


export const {  } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very basic structure. just create a variable and inject BaseApi. finally export it. ✅✅&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: C for Create 😅&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;createDriverSalary: build.mutation({
      query: (data: any) =&amp;gt; ({
        url: `/driver-salary/create`,
        method: "POST",
        data: data,
      }),
      invalidatesTags: ['salary'],
    }),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the build.mutation method, we can create anything. The baseURL is already added in the baseHome, so we don’t need to add the full URL repeatedly. Only just the endpoints. Finally export it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const { useCreateDriverSalaryMutation } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After typing use and the variable name, it will auto-import, so there's no need to worry about it.&lt;/p&gt;

&lt;p&gt;Now just go to your page.tsx where you use this ✅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [createDriverSalary] = useCreateDriverSalaryMutation();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import that mutation and use it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const onSubmit = async (data: any) =&amp;gt; {
    try {
      const res = await createDriverSalary(data);
      if(res){
        console.log("res:", res)
      }
    } catch (error) {
      console.log("driver salary error", error);
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: R for Read 😅&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a getAll route.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getAllDriverSalary: build.query({
      query: (page) =&amp;gt; ({
        url: `/driver-salary/list`,
        method: "GET",
      }),
      providesTags: ['salary'],
    }),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and export like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const { useGetAllDriverSalaryQuery } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to page.tsx and import our created query ✅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { data: salaryDriver, isFetching, isLoading, } = useGetAllDriverSalaryQuery("");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;finally console.log salaryDriver you will see the result..&lt;/p&gt;

&lt;p&gt;getSingle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getSingleDriverSalary: build.query({
      query: (id: any) =&amp;gt; ({
        url: `/driver-salary/single/${id}`,
        method: "GET",
      }),
      providesTags: ['salary'],
    }),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and export it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const { useGetSingleDriverSalaryQuery } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;finally go to that page.tsx ✅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { data: driverSalarySingle } = useGetSingleDriverSalaryQuery("SINGLE ID PASS HERE");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the getSingle route, we just need to pass the ID. The rest is the same as getAll. We can also use isLoading, isFetching, or isError here. For more information, you can refer to the documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: D for Delete😅&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;deleteDriverSalary: build.mutation({
      query: (id: any) =&amp;gt; ({
        url: `/driver-salary/delete/${id}`,
        method: "DELETE",
      }),
      invalidatesTags: ['salary'],
    }),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And export it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const { useDeleteDriverSalaryMutation } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the page.tsx ✅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [deleteDriverSalary] = useDeleteDriverSalaryMutation();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;finally, use a handler function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const onHandleDelete = async (data: any) =&amp;gt; {
    try {
      const res = await deleteDriverSalary("DELETE ID");
      if(res){
        console.log("res:", res)
      }
    } catch (error) {
      console.log("driver salary error", error);
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: U for Update😅&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remember that for updates, you need the ID as well as the updated data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;updateSingleUse: build.mutation({
            query: ({ id, ...data }) =&amp;gt; ({
                url: `vehicle/update/${id}`,
                method: 'PATCH',
                data: data
            }),
            invalidatesTags: [tagTypes.user]
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For updates, look at the method. If your backend API uses the PUT method, then use PUT, and if it uses the PATCH method, then use PATCH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const { useUpdateDriverSalaryMutation } = driverSalaryApi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And uses&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [updateSingleUser] = useUpdateSingleUseMutation();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then collect the updated data. Here, I’m using a simple variable, but in a real-life scenario, you would get your data from a form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const updateData = {
        price: 10000,
        tax: 1000
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, Now we will use handler function to trigger the API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleUpdateData = async () =&amp;gt; {
        const res = await updateSingleUser({
            id: '65d098133a2e34cc13f13551',
            ...updateData
        });
        console.log(':rocket: ~ handleUpdateData ~ res:', res);
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you now have an idea of how to use Redux Toolkit. Thanks for reading. ☑☑☑&lt;/p&gt;

</description>
      <category>redux</category>
      <category>crud</category>
      <category>react</category>
      <category>api</category>
    </item>
    <item>
      <title>Node Docker App</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Sat, 13 Jul 2024 05:00:00 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/node-docker-app-2f1e</link>
      <guid>https://dev.to/nisharga_kabir/node-docker-app-2f1e</guid>
      <description>&lt;p&gt;Our Funda is very simple. Just create a simple nodeJs app and dockerize it docker hub😘 ...&lt;/p&gt;

&lt;p&gt;Step 0: create a folder and create a package.json file. and copy these code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "nodejs-image-demo",
  "version": "1.0.0",
  "description": "nodejs image demo",
  "author": "Nisharga Kabir",
  "license": "MIT",
  "main": "app.js",
  "keywords": [
    "nodejs",
    "bootstrap",
    "express"
  ],
  "dependencies": {
    "express": "^4.16.4"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then do this command&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is nothing... just npm init and and doing some answers we can easily make this. but for fast going we ignore this process.&lt;/p&gt;

&lt;p&gt;Please make sure you have installed node js and docker on your PC. (you will find lots of videos on YouTube to install docker and nodejs)&lt;/p&gt;

&lt;p&gt;Let's Start the Game 😍😍😍&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: create &lt;strong&gt;app.js&lt;/strong&gt;  on root and peast this code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const app = express();
const router = express.Router();


const path = __dirname + "/views/";
const port = 8080;


router.use(function (req, res, next) {
  console.log("/" + req.method);
  next();
});


router.get("/", function (req, res) {
  res.sendFile(path + "index.html");
});


router.get("/sharks", function (req, res) {
  res.sendFile(path + "sharks.html");
});


app.use(express.static(path));
app.use("/", router);


app.listen(port, function () {
  console.log("Example app listening on port 8080!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code says nothing. First, we do a basic setup of express.&lt;br&gt;
Then we got pathName and port for future use. _ _ dirname is the absolute path of a file.&lt;br&gt;
Next, we use console.log to see what request we are doing.&lt;/p&gt;

&lt;p&gt;Using res.sendFile we say / will be the index.html route&lt;br&gt;
And /sharks will be sharks.html route&lt;/p&gt;

&lt;p&gt;Finally specifically said path and app. use router&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: create two file &lt;strong&gt;views/index.html&lt;/strong&gt; and &lt;strong&gt;views/sharks.html&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;(make sure to create views folder)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.html&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;About Sharks&amp;lt;/title&amp;gt;
    &amp;lt;meta charset="utf-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1"&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"&amp;gt;
    &amp;lt;link href="css/styles.css" rel="stylesheet"&amp;gt;
    &amp;lt;link href="https://fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css"&amp;gt;
&amp;lt;/head&amp;gt;


&amp;lt;body&amp;gt;
    &amp;lt;nav class="navbar navbar-dark bg-dark navbar-static-top navbar-expand-md"&amp;gt;
        &amp;lt;div class="container"&amp;gt;
            &amp;lt;button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"&amp;gt; &amp;lt;span class="sr-only"&amp;gt;Toggle navigation&amp;lt;/span&amp;gt;
            &amp;lt;/button&amp;gt; &amp;lt;a class="navbar-brand" href="#"&amp;gt;Everything Sharks&amp;lt;/a&amp;gt;
            &amp;lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&amp;gt;
                &amp;lt;ul class="nav navbar-nav mr-auto"&amp;gt;
                    &amp;lt;li class="active nav-item"&amp;gt;&amp;lt;a href="/" class="nav-link"&amp;gt;Home&amp;lt;/a&amp;gt;
                    &amp;lt;/li&amp;gt;
                    &amp;lt;li class="nav-item"&amp;gt;&amp;lt;a href="/sharks" class="nav-link"&amp;gt;Sharks&amp;lt;/a&amp;gt;
                    &amp;lt;/li&amp;gt;
                &amp;lt;/ul&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/nav&amp;gt;
    &amp;lt;div class="jumbotron"&amp;gt;
        &amp;lt;div class="container"&amp;gt;
            &amp;lt;h1&amp;gt;Want to Learn About Sharks?&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;Are you ready to learn about sharks?&amp;lt;/p&amp;gt;
            &amp;lt;br&amp;gt;
            &amp;lt;p&amp;gt;&amp;lt;a class="btn btn-primary btn-lg" href="/sharks" role="button"&amp;gt;Get Shark Info Now&amp;lt;/a&amp;gt;
            &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;div class="row"&amp;gt;
            &amp;lt;div class="col-lg-6"&amp;gt;
                &amp;lt;h3&amp;gt;Not all sharks are alike&amp;lt;/h3&amp;gt;
                &amp;lt;p&amp;gt;Though some are dangerous, sharks generally do not attack humans. Out of the 500 species known to researchers, only 30 have been known to attack humans.
                &amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-lg-6"&amp;gt;
                &amp;lt;h3&amp;gt;Sharks are ancient&amp;lt;/h3&amp;gt;
                &amp;lt;p&amp;gt;There is evidence to suggest that sharks lived up to 400 million years ago.
                &amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;


&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;sharks.html&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;About Sharks&amp;lt;/title&amp;gt;
    &amp;lt;meta charset="utf-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1"&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"&amp;gt;
    &amp;lt;link href="css/styles.css" rel="stylesheet"&amp;gt;
    &amp;lt;link href="https://fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;nav class="navbar navbar-dark bg-dark navbar-static-top navbar-expand-md"&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"&amp;gt; &amp;lt;span class="sr-only"&amp;gt;Toggle navigation&amp;lt;/span&amp;gt;
        &amp;lt;/button&amp;gt; &amp;lt;a class="navbar-brand" href="/"&amp;gt;Everything Sharks&amp;lt;/a&amp;gt;
        &amp;lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&amp;gt;
            &amp;lt;ul class="nav navbar-nav mr-auto"&amp;gt;
                &amp;lt;li class="nav-item"&amp;gt;&amp;lt;a href="/" class="nav-link"&amp;gt;Home&amp;lt;/a&amp;gt;
                &amp;lt;/li&amp;gt;
                &amp;lt;li class="active nav-item"&amp;gt;&amp;lt;a hreaf="/sharks" class="nav-link"&amp;gt;Sharks&amp;lt;/a&amp;gt;
                &amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/nav&amp;gt;
&amp;lt;div class="jumbotron text-center"&amp;gt;
    &amp;lt;h1&amp;gt;Shark Info&amp;lt;/h1&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-lg-6"&amp;gt;
            &amp;lt;p&amp;gt;
                &amp;lt;div class="caption"&amp;gt;Some sharks are known to be dangerous to humans, though many more are not. The sawshark, for example, is not considered a threat to humans.
                &amp;lt;/div&amp;gt;
                &amp;lt;img src="https://assets.digitalocean.com/articles/docker_node_image/sawshark.jpg" alt="Sawshark"&amp;gt;
            &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="col-lg-6"&amp;gt;
            &amp;lt;p&amp;gt;
                &amp;lt;div class="caption"&amp;gt;Other sharks are known to be friendly and welcoming!&amp;lt;/div&amp;gt;
                &amp;lt;img src="https://assets.digitalocean.com/articles/docker_node_image/sammy.png" alt="Sammy the Shark"&amp;gt;
            &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally &lt;strong&gt;views/css/style.css&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;.navbar {
    margin-bottom: 0;
}


body {
    background: #020A1B;
    color: #ffffff;
    font-family: 'Merriweather', sans-serif;
}


h1,
h2 {
    font-weight: bold;
}


p {
    font-size: 16px;
    color: #ffffff;
}


.jumbotron {
    background: #0048CD;
    color: white;
    text-align: center;
}


.jumbotron p {
    color: white;
    font-size: 26px;
}


.btn-primary {
    color: #fff;
    text-color: #000000;
    border-color: white;
    margin-bottom: 5px;
}


img,
video,
audio {
    margin-top: 20px;
    max-width: 80%;
}


div.caption: {
    float: left;
    clear: both;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now do this command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node app.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will start the server and you will start your node app 🙂&lt;br&gt;
And visit this URL &lt;code&gt;http://localhost:8080/&lt;/code&gt; you will see your app running.&lt;/p&gt;

&lt;p&gt;I am not describing code here. If you are here to learn node-docker I believe you already know HTML,CSS, and Bootstrap 😎😎😎&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: DockerFile create
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;Dockerfile&lt;/code&gt; on root and peast this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:16-alpine


WORKDIR /app


COPY . .


RUN npm install


EXPOSE 3000


CMD [ "node", "app.js" ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we just say brother. take version 16 (alphine lite version) when you create container inside that app folder our app code will store. copy everything. this install all dependency and finally run it 3000 port with node command 😎&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.dockerignore&lt;/code&gt; create on root&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules;
npm - debug.log;
Dockerfile.dockerignore;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is just because we don't want node_modules folder and others stuff. 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Build And Run
&lt;/h2&gt;

&lt;p&gt;open docker app first then&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t your_dockerhub_username/nodejs-image-demo .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I am doing here &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t nisharga/nodeapp .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are doing this command. -t means tagname we do it blank but if you wants you can set 🙂&lt;/p&gt;

&lt;p&gt;Lets check image created or not by this command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker images&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;REPOSITORY                                    TAG       IMAGE ID       CREATED         SIZE&lt;/p&gt;

&lt;p&gt;We see more about these……. Repo is name. Tag is version id is specific thing. Created is time and size is size &lt;/p&gt;

&lt;p&gt;NOW ITS TIME TO BUILD AND RUN 😀&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t nkapp . &amp;amp;&amp;amp; docker run -p 1200:8080 nkapp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now just do these command, -t means tagName -p means port.&lt;br&gt;
-p 1200:8080 means our app is running on port 8080 and we are now running our docker app in 1200 port override 8080.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:1200/&lt;/code&gt; Visit these URL you will see live app from docker build file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Push the code to docker hub
&lt;/h2&gt;

&lt;p&gt;First register in hub.docker then do these command &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker login -u DOCKER_NAME&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then write password and login 🙂 &lt;/p&gt;

&lt;p&gt;Now Docker image Push to hubDocker&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t nisharga/nkapp2:latest .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker push nisharga/nkapp2:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I am building twice to remove confusion. I believe you are already familiar with GitHub. so you already know &lt;/p&gt;

&lt;p&gt;githubUserName/RepoName/branchName &lt;/p&gt;

&lt;p&gt;here 100% same to same to same thing. BranchName called here tagName. Repo is using appName. The username is used here dockerUser.&lt;/p&gt;

&lt;p&gt;Now visit Docker Hub to see your code on docker. Now you can share with dockerize image with anyone, does not matter what device he is using he can easily run it with docker app 😎😎😎😎😎😎&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Github Source Code:&lt;/strong&gt; &lt;a href="https://github.com/nisharga/node-docker" rel="noopener noreferrer"&gt;https://github.com/nisharga/node-docker&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>nodeapp</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Implement ShadCn form with Validation</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Wed, 03 Jul 2024 10:07:24 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/implement-shadcn-form-with-validation-3hik</link>
      <guid>https://dev.to/nisharga_kabir/implement-shadcn-form-with-validation-3hik</guid>
      <description>&lt;p&gt;Our Goal or Funda is very simple. Follow 4 steps implement a super duper form with validation with less code &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 0: Define a zod schema&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { z } from 'zod';

export const createDepartmentsSchema = z.object({ 
    name: z.string().min(2, {
        message: 'Please enter your full name'
    }),
    remarks: z.string().min(2, {
        message: 'Subject must be at least 2 characters'
    }),
    description: z.string().min(20, {
        message: 'Message must be at least 20 characters'
    }), 
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;schema is nothing....... if you work with mongoose you already know it otherwise just think it just like typescript. whatever condition you write here if its not match it will show you this message on the UI.&lt;br&gt;
(for more about zod schema you can google it)&lt;/p&gt;

&lt;p&gt;Now start the process :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1. Define your form.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const form = useForm&amp;lt;z.infer&amp;lt;typeof createDepartmentsSchema&amp;gt;&amp;gt;({
     resolver: zodResolver(createDepartmentsSchema),
        defaultValues: {
         name: '',
         remarks: '',
         description: ''
      }
});


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;using zodResolver connect your schema with form...&lt;br&gt;
when you update you can set your current value on default values...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2. Define a submit handler.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 function onSubmit(values: z.infer&amp;lt;typeof createDepartmentsSchema&amp;gt;) {
        console.log(values);
 }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;currently we do console.log here to see our form data.. later we will implement API here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3. Init your form&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 &amp;lt;Form {...form}&amp;gt;
   &amp;lt;form
    onSubmit={form.handleSubmit(onSubmit)}
    className='space-y-6'&amp;gt;


    &amp;lt;/form&amp;gt;
&amp;lt;/Form&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;First Form came from ShadCN which expect default values thats why we copy our form data. (step 1)&lt;br&gt;
form onSumit is the default behavior of a form. we are already familer with it.. our 90% job done here ✅&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Final Step (Now its time to import input)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you need a input field you can use your reUsable formInput (or you can use shadcn input here)...&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;FormInput
   form={form}
   name='name'
   placeholder='Your Name'
   className='!pl-8 rounded-full'
/&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;FormInput just expert (form) you can think it just a connection creator between input and forms 😁&lt;/p&gt;

&lt;p&gt;If you need Textarea&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;FormTextarea form={form} name='description' /&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;remember only form and name is required in every field. other fields are optional...&lt;/p&gt;

&lt;p&gt;Finally a button need for submitting this form.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;Button type='submit'&amp;gt;Submit&amp;lt;Button&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If everything works... then without data submitting form show warring....&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%2Fh92e9k859cpoxvyfhot1.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%2Fh92e9k859cpoxvyfhot1.png" alt="without validation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If everything ok then.....&lt;br&gt;
After submit data show data on console.&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%2Fp9n8jvczxp5m9dxihli3.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%2Fp9n8jvczxp5m9dxihli3.png" alt="after submit console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤❤❤&lt;/p&gt;

</description>
      <category>reacthookform</category>
      <category>zod</category>
      <category>validation</category>
      <category>shadcn</category>
    </item>
    <item>
      <title>Debounce Method for Searching</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Sun, 23 Jun 2024 06:11:44 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/debounce-method-for-searching-25nc</link>
      <guid>https://dev.to/nisharga_kabir/debounce-method-for-searching-25nc</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Debounce?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Debounce is nothing but a programming pattern for delaying the execution of a function or something...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we use it? or Why is it important?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Look at this code.....&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;input type='text' onChange={(e) =&amp;gt; console.log(e.target.value)} /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and its output........&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fut3w1dv3sd1tho1oqy1z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fut3w1dv3sd1tho1oqy1z.png" alt="Without Debounce" width="299" height="689"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We type simple 2 words but it's calling 14 times!! If we integrate Search API here our API will be called 14 times for these words. &lt;/p&gt;

&lt;p&gt;It will be costly for us. That is why the Debounce Method played its role in waiting some time and getting the result.&lt;/p&gt;

&lt;p&gt;create a hook or a function for debounce 😎😎&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const useDebounced = ({ searchQuery, delay }) =&amp;gt; {
        const [debouncedValue, setDebouncedValue] =
            useState(searchQuery);
        useEffect(() =&amp;gt; {
            const handler = setTimeout(() =&amp;gt; {
                setDebouncedValue(searchQuery);
            }, delay);
            return () =&amp;gt; {
                clearTimeout(handler);
            };
        }, [searchQuery, delay]);

        return debouncedValue;
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do we do here...?? as a parameter we need two things searchQuery and delay time..&lt;/p&gt;

&lt;p&gt;using useState we set our value here. and later we return it.&lt;br&gt;
we use useEffect for calling this process infinite time changing searchQuery or delay value change it will be calling.&lt;/p&gt;

&lt;p&gt;then we use a setTimeout function. its nothing just a prebuild function in javascript which is calling after a certain time.&lt;br&gt;&lt;br&gt;
and clearTimeout is another function for stoping that setTimeout function.&lt;/p&gt;

&lt;p&gt;What is the logic behind this setTimeout and clearTimeOut here? Well we want the user to type something... After he writes the first character when he writes another character between the delay time stop calling the setTimeout here. finally return it&lt;/p&gt;

&lt;p&gt;Now its time to implement it 🤩🤩&lt;/p&gt;

&lt;p&gt;before return your nextjs or react component add this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [value, setValue] = useState('');

const debouncedValue = useDebounced({ searchQuery: value, delay: 600 });  

console.log(debouncedValue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and your input field&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type='text' onChange={(e) =&amp;gt; setValue(e.target.value)} /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain these two things. in inputs we set our values to the state value.&lt;br&gt;
Then calling that function and as parameter pass our e.target.value and a delay time. finally console.log it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj950x31epeuyqu3at2ru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj950x31epeuyqu3at2ru.png" alt="After Apply Debounce" width="338" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now see just calling two or three times base on our typing speed this debounce method will call 😍😍&lt;/p&gt;

</description>
      <category>searching</category>
      <category>javascript</category>
      <category>debounce</category>
      <category>debouncing</category>
    </item>
    <item>
      <title>Reusable React Hook Form</title>
      <dc:creator>NISHARGA KABIR</dc:creator>
      <pubDate>Sat, 22 Jun 2024 06:26:47 +0000</pubDate>
      <link>https://dev.to/nisharga_kabir/reusable-react-hook-form-dmb</link>
      <guid>https://dev.to/nisharga_kabir/reusable-react-hook-form-dmb</guid>
      <description>&lt;p&gt;We will use typescript with nextjs but you can use it as your wish funda is same as this ☺️☺️☺️ &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install:&lt;/strong&gt; &lt;code&gt;npm install react-hook-form&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a &lt;code&gt;Form.tsx&lt;/code&gt; file&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;import { useForm, FormProvider, SubmitHandler } from 'react-hook-form';
import React from 'react';

interface FormProps {
    children: React.ReactNode;
    defaultValues?: Record&amp;lt;string, any&amp;gt;;
    submitHandler: SubmitHandler&amp;lt;Record&amp;lt;string, any&amp;gt;&amp;gt;;
}

const Form = ({ children, defaultValues, submitHandler }: FormProps) =&amp;gt; {
    const methods = useForm({ defaultValues });
    const { handleSubmit, reset } = methods;

    const onSubmit: SubmitHandler&amp;lt;Record&amp;lt;string, any&amp;gt;&amp;gt; = (data) =&amp;gt; {
        submitHandler(data);
        reset(defaultValues); // Reset to default values after submit
    };

    return (
        &amp;lt;FormProvider {...methods}&amp;gt;
            &amp;lt;form onSubmit={handleSubmit(onSubmit)}&amp;gt;{children}&amp;lt;/form&amp;gt;
        &amp;lt;/FormProvider&amp;gt;
    );
};

export default Form;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Heres we do nothing. Just do copy peast from react hook form doc. 😅&lt;/p&gt;

&lt;p&gt;We needs 3 things as perameter. &lt;strong&gt;Default value&lt;/strong&gt;, &lt;strong&gt;submit handler&lt;/strong&gt;  and &lt;strong&gt;children&lt;/strong&gt;….&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default value is used for user experience. We can reset it after form submits or we can handle it in our way.&lt;/li&gt;
&lt;li&gt;Submit handler is the same thing you use in html… e.target.value do you forget it? It's the same.&lt;/li&gt;
&lt;li&gt;And children no need to describe whatever you pass it it will take it. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;FormProps is typescript declare you can ignore it. Now start the main agenda.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the method variable, we take useForm which is the preBuild function for reactHookForm and as input, we pass our default value. Finally calling it into our formProvider.&lt;/p&gt;

&lt;p&gt;Then handleSubmit and reset we destrure from methods. onSubmit Function  &lt;/p&gt;

&lt;p&gt;Form &amp;gt; form onSubmit &amp;gt; We use that handleSubmit function&lt;/p&gt;

&lt;p&gt;And inside the onSubmit function we use reset….&lt;/p&gt;

&lt;p&gt;And last one thing submitHandler came from reactHookForm &lt;/p&gt;

&lt;p&gt;Inside the return function, we use the same convention as reactHookForm suggests us…… Our 60% job done. Now move to step 2;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create a &lt;code&gt;FormInput.tsx&lt;/code&gt; file&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;import { Controller, useFormContext } from 'react-hook-form';

interface FormInputProps {
    name: string;
    type: string;
    placeholder?: string;
}

const FormInput = ({ name, type, placeholder }: FormInputProps) =&amp;gt; {
    const { control } = useFormContext();
    return (
        &amp;lt;Controller
            control={control}
            name={name}
            render={({ field }) =&amp;gt; (
                &amp;lt;input type={type} placeholder={placeholder} {...field} /&amp;gt;
            )}
        /&amp;gt;
    );
};

export default FormInput;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, we are working here only name, type, and placeholder. If you want you can work with lots of things it depends on which CSS framework you use. We are using nothing.&lt;/p&gt;

&lt;p&gt;We mainly need a controller component that came from reactHookForm.&lt;/p&gt;

&lt;p&gt;Which expect three things. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;control&lt;/li&gt;
&lt;li&gt;name &lt;/li&gt;
&lt;li&gt;render&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Control is came from useFromContect Hook which is a preBuild thing for reactHookForm. No need to create it.&lt;/li&gt;
&lt;li&gt;The name is same thing as we use in html input..&lt;/li&gt;
&lt;li&gt;Using render method we will got field. Whatever things we pass into our inputs it will take it. As example in our form we pass size=”lg” so it will set here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our 95% work done. Now its time to use it. 😍😍 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: create a file or in the &lt;code&gt;app.ts&lt;/code&gt; / &lt;code&gt;app.js&lt;/code&gt; file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;before return peast this&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const onSubmit = (data: Record&amp;lt;string, any&amp;gt;) =&amp;gt; {&lt;br&gt;
        console.log(data);&lt;br&gt;
 };&lt;/code&gt;&lt;br&gt;
this is nothing to describe in HTML lots of times you use it.&lt;/p&gt;

&lt;p&gt;and &lt;br&gt;
inside return &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Form submitHandler={onSubmit} defaultValues={{ name: '' }}&amp;gt;&lt;br&gt;
    &amp;lt;FormInput type='text' name='name' placeholder='Name' /&amp;gt;&lt;br&gt;
    &amp;lt;input type='submit' value='send' /&amp;gt;&lt;br&gt;
&amp;lt;/Form&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Form and FormInput in our created Step1 and Step2 file. submitHandler came from reactHookForm and defaultValue whatever you wants you can pass. just remember its just a pattern of name field.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6mo2jr6115ravffxpal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6mo2jr6115ravffxpal.png" alt="live looks like this" width="493" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will looks like this and after form submit we will got our values 😍😍😍&lt;/p&gt;

</description>
      <category>reusable</category>
      <category>hook</category>
      <category>form</category>
      <category>react</category>
    </item>
  </channel>
</rss>
