<?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: Rakib Hasan</title>
    <description>The latest articles on DEV Community by Rakib Hasan (@mrakib007).</description>
    <link>https://dev.to/mrakib007</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%2F1004393%2Fb5b906a3-6751-421c-afeb-f3b310e078e3.jpg</url>
      <title>DEV Community: Rakib Hasan</title>
      <link>https://dev.to/mrakib007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrakib007"/>
    <language>en</language>
    <item>
      <title>Next.js: A Deep Dive into the Game-Changing React Library</title>
      <dc:creator>Rakib Hasan</dc:creator>
      <pubDate>Tue, 04 Apr 2023 10:05:56 +0000</pubDate>
      <link>https://dev.to/mrakib007/nextjs-a-deep-dive-into-the-game-changing-react-library-4oi0</link>
      <guid>https://dev.to/mrakib007/nextjs-a-deep-dive-into-the-game-changing-react-library-4oi0</guid>
      <description>&lt;p&gt;If you're a web developer who's interested in creating server-side rendered (SSR) React applications, Next.js is one of the best options you've got. I recently started learning Next.js and wanted to share my first impressions of this powerful framework.&lt;/p&gt;

&lt;p&gt;One of the first things that struck me about Next.js If you're a web developer who's interested in building server-side rendered (SSR) React applications, Next.js is a powerful framework that can help streamline your development process. In this post, we'll take a closer look at Next.js and explore some of its key features and benefits.&lt;/p&gt;

&lt;p&gt;One of the major advantages of Next.js is its built-in support for SSR. This means that the initial HTML is generated on the server and sent to the client, which can improve performance and SEO. With other frameworks, you may need to set up SSR yourself, which can be a time-consuming process.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example of how SSR works in Next.js. Suppose you have a simple React component that fetches some data from an API and displays it on the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from 'react';

function MyComponent() {
  const [data, setData] = useState([]);

  useEffect(() =&amp;gt; {
    fetch('/api/data')
      .then(response =&amp;gt; response.json())
      .then(data =&amp;gt; setData(data));
  }, []);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;My Component&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
        {data.map(item =&amp;gt; (
          &amp;lt;li key={item.id}&amp;gt;{item.name}&amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default MyComponent;

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

&lt;/div&gt;



&lt;p&gt;Normally, when you render this component in the browser, the data will be fetched and displayed on the page after the initial HTML has loaded. However, with SSR in Next.js, you can generate the HTML on the server and send it to the client with the data already included. Here's how you can modify the component to support SSR:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from 'react';

function MyComponent({ data }) {
  const [localData, setLocalData] = useState(data);

  useEffect(() =&amp;gt; {
    fetch('/api/data')
      .then(response =&amp;gt; response.json())
      .then(data =&amp;gt; setLocalData(data));
  }, []);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;My Component&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
        {localData.map(item =&amp;gt; (
          &amp;lt;li key={item.id}&amp;gt;{item.name}&amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export async function getServerSideProps() {
  const response = await fetch('https://api.example.com/data');
  const data = await response.json();

  return {
    props: {
      data,
    },
  };
}

export default MyComponent;

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

&lt;/div&gt;



&lt;p&gt;In this modified version of the component, we've added a &lt;code&gt;getServerSideProps&lt;/code&gt; function that fetches the data from an API and passes it to the component as a prop. We've also modified the &lt;code&gt;useState&lt;/code&gt; hook to use the data that's passed in as a prop, and added an additional fetch to update the data on the client side.&lt;/p&gt;

&lt;p&gt;With this setup, Next.js will generate the HTML on the server and send it to the client with the data already included. This can help improve the performance of your application, especially if you have a lot of dynamic content that needs to be fetched and rendered.&lt;/p&gt;

&lt;p&gt;Another feature of Next.js that I found helpful was its folder-based routing system. This allows you to create routes based on the structure of your project's file system. For example, if you have a file named &lt;code&gt;pages/about.js&lt;/code&gt;, it will automatically create a route for &lt;code&gt;/about&lt;/code&gt;. This can make it easier to organize your code and create a clear, predictable URL structure.&lt;/p&gt;

&lt;p&gt;Here's an example of how folder-based routing works in Next.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pages/
--| index.js
--| about/
-----| index.js
-----| team.js

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

&lt;/div&gt;



&lt;p&gt;In this example, we have an &lt;code&gt;index.js&lt;/code&gt; file in the root &lt;code&gt;pages&lt;/code&gt; directory, as well as an &lt;code&gt;about&lt;/code&gt; directory that contains two files: an &lt;code&gt;index.js&lt;/code&gt; file and a &lt;code&gt;team.js&lt;/code&gt; file. With folder-based routing, the &lt;code&gt;index.js&lt;/code&gt; file in the root directory corresponds to the root URL (/), while the &lt;code&gt;index.js&lt;/code&gt; file in the about directory corresponds to the &lt;code&gt;/about&lt;/code&gt; URL. The &lt;code&gt;team.js&lt;/code&gt; file in the &lt;code&gt;about&lt;/code&gt; directory corresponds to the &lt;code&gt;/about/team&lt;/code&gt; URL.&lt;/p&gt;

&lt;p&gt;In my experience, getting started with Next.js was relatively straightforward. I used the &lt;code&gt;create-next-app&lt;/code&gt; CLI tool to set up a new project, and then began exploring the framework's features. The official Next.js documentation is well-written and provides helpful examples, so I was able to quickly get up to speed. &lt;br&gt;
Here is the official documentation link : &lt;a href="https://nextjs.org/docs" rel="noopener noreferrer"&gt;Getting Started With Next.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One drawback of Next.js is that it has a bit of a learning curve, especially if you're new to React or SSR. However, with some patience and persistence, I was able to overcome this hurdle and start building my first Next.js application.&lt;/p&gt;

&lt;p&gt;Overall, I would definitely recommend Next.js to other developers who are interested in server-side rendering or building React applications. Its built-in support for SSR and folder-based routing make it a powerful and convenient tool, and its growing community means there are plenty of resources available for learning and troubleshooting.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>ssr</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>"Streamlining Data Management in React with React Query: A Comprehensive Guide and Sample Project"</title>
      <dc:creator>Rakib Hasan</dc:creator>
      <pubDate>Fri, 31 Mar 2023 06:34:43 +0000</pubDate>
      <link>https://dev.to/mrakib007/streamlining-data-management-in-react-with-react-query-a-comprehensive-guide-and-sample-project-3jki</link>
      <guid>https://dev.to/mrakib007/streamlining-data-management-in-react-with-react-query-a-comprehensive-guide-and-sample-project-3jki</guid>
      <description>&lt;p&gt;React Query is a powerful data management library that simplifies data fetching, caching, and updating in React applications. With its simple, declarative API and support for complex data scenarios like pagination and optimistic updates, React Query is a great choice for any React developer looking to streamline their data management code.&lt;/p&gt;

&lt;p&gt;One of the key benefits of React Query is its ability to cache data and automatically handle stale data. This means that if a component needs to render data that has already been fetched, React Query will return the cached data rather than making a new network request.&lt;/p&gt;

&lt;p&gt;Additionally, React Query includes a number of features that make it easy to manage complex data fetching scenarios, such as pagination, optimistic updates, and polling.&lt;/p&gt;

&lt;p&gt;Now that we've covered the basics, let's dive into some of the key features of React Query&lt;/p&gt;

&lt;p&gt;-- Querying Data:&lt;br&gt;
At its core, React Query is all about fetching and managing data. To fetch data, you can use the &lt;code&gt;useQuery&lt;/code&gt; hook, which takes a query key and an async function that returns the data you want to fetch. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from 'react-query'

function MyComponent() {
  const { isLoading, data } = useQuery('todos', async () =&amp;gt; {
    const response = await fetch('/api/todos')
    return response.json()
  })

  if (isLoading) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;

  return (
    &amp;lt;ul&amp;gt;
      {data.map(todo =&amp;gt; (
        &amp;lt;li key={todo.id}&amp;gt;{todo.title}&amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;p&gt;In this example, we're fetching a list of todos from an API and rendering them in a list. The &lt;code&gt;useQuery&lt;/code&gt; hook takes a string key ('todos') that is used to cache the results, as well as an async function that fetches the data.&lt;/p&gt;

&lt;p&gt;-- Mutating Data:&lt;br&gt;
In addition to fetching data, React Query also provides a way to &lt;code&gt;mutate&lt;/code&gt; data using the &lt;code&gt;useMutation&lt;/code&gt; hook. This hook takes a mutation function that performs the update on the server, and returns an object with a mutate function that you can call to trigger the mutation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMutation, useQueryClient } from 'react-query'

function AddTodo() {
  const queryClient = useQueryClient()

  const { mutate, isLoading } = useMutation(
    async (todo) =&amp;gt; {
      const response = await fetch('/api/todos', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(todo)
      })
      return response.json()
    },
    {
      onSuccess: () =&amp;gt; {
        queryClient.invalidateQueries('todos')
      }
    }
  )

  const handleSubmit = async (e) =&amp;gt; {
    e.preventDefault()
    const { value } = e.target.elements.title
    mutate({ title: value })
  }

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;input type="text" name="title" /&amp;gt;
      &amp;lt;button type="submit" disabled={isLoading}&amp;gt;
        {isLoading ? 'Adding...' : 'Add'}
      &amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;p&gt;In this example, we're using the &lt;code&gt;useMutation&lt;/code&gt; hook to add a new todo to the server. The &lt;code&gt;mutate&lt;/code&gt; function takes an object with the data to be added, and automatically updates the cache with the new data when the mutation is successful.&lt;/p&gt;

&lt;p&gt;--Paginating Data: &lt;br&gt;
Another common scenario in data fetching is pagination. React Query makes it easy to implement pagination using the &lt;code&gt;useInfiniteQuery&lt;/code&gt; hook, which allows you to fetch data in chunks and add them to the cache as they are loaded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useInfiniteQuery } from 'react-query'

function MyComponent() {
  const { data, error, fetchNextPage, hasNextPage, isFetching } = useInfiniteQuery(
    'todos',
    ({ pageParam = 0 }) =&amp;gt; fetch(`/api/todos?page=${pageParam}`).then(res =&amp;gt; res.json()),
    {
      getNextPageParam: (lastPage) =&amp;gt; lastPage.nextPage,
    }
  )

  if (error) return &amp;lt;div&amp;gt;Error fetching data&amp;lt;/div&amp;gt;

  return (
    &amp;lt;&amp;gt;
      {data.pages.map(page =&amp;gt; (
        &amp;lt;ul key={page.pageNumber}&amp;gt;
          {page.todos.map(todo =&amp;gt; (
            &amp;lt;li key={todo.id}&amp;gt;{todo.title}&amp;lt;/li&amp;gt;
          ))}
        &amp;lt;/ul&amp;gt;
      ))}

      &amp;lt;button onClick={() =&amp;gt; fetchNextPage()} disabled={!hasNextPage || isFetching}&amp;gt;
        {isFetching ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load'}
      &amp;lt;/button&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;p&gt;In this example, we're using the &lt;code&gt;useInfiniteQuery&lt;/code&gt; hook to fetch todos in pages from an API. The &lt;code&gt;fetchNextPage&lt;/code&gt; function is used to load the next page of todos, and the &lt;code&gt;hasNextPage&lt;/code&gt; property is used to disable the "Load More" button when there are no more pages to fetch.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;getNextPageParam&lt;/code&gt; function is used to return the &lt;code&gt;nextPage&lt;/code&gt; value from the last page of data, which is used to fetch the next page of data.&lt;/p&gt;

&lt;p&gt;If you want to learn more about React Query, there are many resources available online. One great place to start is the official React Query documentation, which provides detailed information on how to use the library. &lt;br&gt;
&lt;a href="https://tanstack.com/query/v3/docs/react/overview" rel="noopener noreferrer"&gt;Official Documentation Link:&lt;/a&gt; &lt;br&gt;
Here is the official documentation of the library.&lt;/p&gt;

&lt;p&gt;Additionally, there are many excellent YouTube tutorials available that cover React Query in-depth. One such channel is Code Evolution, which has a comprehensive React Query tutorial series that covers everything from basic usage to advanced topics like pagination and optimistic updates. Here is the playlist link that I have followed and it's great if you ask me.&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=VtWkSCZX0Ec&amp;amp;list=PLC3y8-rFHvwjTELCrPrcZlo6blLBUspd2&amp;amp;index=1" rel="noopener noreferrer"&gt;Youtube playlist that I have followed&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to see React Query in action, you can check out a sample project that uses the library. I have created a GitHub repo that contains a simple React application that fetches data from an API using React Query. The project also demonstrates how to implement pagination using the &lt;code&gt;useInfiniteQuery&lt;/code&gt; hook. Here is the repo link that I have created.&lt;br&gt;
&lt;a href="https://github.com/mrakib007/react-query-learning-project" rel="noopener noreferrer"&gt;The project repo&lt;/a&gt;&lt;br&gt;
I have followed the youtube tutorial link that I have given here.&lt;/p&gt;

&lt;p&gt;In conclusion, React Query is a powerful and flexible library that makes it easy to manage data in React applications. Whether you're a beginner or an experienced developer, React Query is definitely worth checking out!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>reactquery</category>
    </item>
    <item>
      <title>Deep Dive into JavaScript.</title>
      <dc:creator>Rakib Hasan</dc:creator>
      <pubDate>Sat, 04 Mar 2023 07:15:06 +0000</pubDate>
      <link>https://dev.to/mrakib007/deep-dive-into-javascript-3fle</link>
      <guid>https://dev.to/mrakib007/deep-dive-into-javascript-3fle</guid>
      <description>&lt;p&gt;JavaScript is one of the most used programming languages right now. With the technologies becoming more and more superior, the need of learning this language is increasing day by day. As a Computer Science I have basic or intermediate level knowledge of C,C++,Java and Python. But last year I took an interest on JavaScript, and I started loving this language. Now I am an entry level React developer preparing for interviews. So I started relearning JavaScript as part of the process. So I want to share this journey with the likes of me who are trying to get into a development job.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mrakib007" rel="noopener noreferrer"&gt;
        mrakib007
      &lt;/a&gt; / &lt;a href="https://github.com/mrakib007/vanilla-js-practice" rel="noopener noreferrer"&gt;
        vanilla-js-practice
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Here I will start javaScript from the very beginning till the advanced level.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
This is the repository where I am keeping all my codes just to check up on it when I need them. &lt;br&gt;
Now, practicing JS from scratch making me love this language even deeper. I hope many JS enthusiasts will find this repo helpful. 

</description>
      <category>welcome</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
