<?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>Forem: Pranav Badami</title>
    <description>The latest articles on Forem by Pranav Badami (@pranav_badami).</description>
    <link>https://forem.com/pranav_badami</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%2F1184432%2F24f96440-527b-4493-90f2-239314f026fd.JPG</url>
      <title>Forem: Pranav Badami</title>
      <link>https://forem.com/pranav_badami</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pranav_badami"/>
    <language>en</language>
    <item>
      <title>Elevate your JavaScript game with essential ES6 tricks!</title>
      <dc:creator>Pranav Badami</dc:creator>
      <pubDate>Sun, 19 Nov 2023 17:21:49 +0000</pubDate>
      <link>https://forem.com/fyno/best-javascript-es6-tricks-514h</link>
      <guid>https://forem.com/fyno/best-javascript-es6-tricks-514h</guid>
      <description>&lt;p&gt;Embracing ES6 (ECMAScript 2015) is like unlocking a treasure trove of features that not only elevate your JavaScript game but also transform your coding journey into a more enjoyable and efficient experience. In this blog, we'll dive into some of the best ES6 tricks that will not only enhance the readability of your code but also empower you to write more concise and expressive programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrow functions
&lt;/h2&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%2Fmiro.medium.com%2Fv2%2F1%2A3BK_UMTK8T2GGnrt4nKhxA.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%2Fmiro.medium.com%2Fv2%2F1%2A3BK_UMTK8T2GGnrt4nKhxA.png" alt="Arrow Function"&gt;&lt;/a&gt;&lt;br&gt;
ES6 introduces arrow functions, providing a more concise syntax for writing anonymous functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function
function add(a, b) {
  return a + b;
}

// Arrow Function
const add = (a, b) =&amp;gt; a + b;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Getting the previous value of the &lt;code&gt;state&lt;/code&gt; in the &lt;code&gt;setState&lt;/code&gt; call using the &lt;code&gt;useState&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// A useState hook initialisation
const [state, setState] = useState(0)

// Updating the state w.r.t to previous value
setState(prev =&amp;gt; prev + 1)

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = ['one','two','three']

// Map through the array
arr.map(number =&amp;gt; (
   console.log(number)
)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Destructuring Literals
&lt;/h2&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%2Ffzle2u1uj0vtn5derqx8.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%2Ffzle2u1uj0vtn5derqx8.png" alt="Destructuring JS literals"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Destructuring allows you to extract values from &lt;code&gt;arrays&lt;/code&gt; or &lt;code&gt;objects&lt;/code&gt; and assign them to variables in a more intuitive way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Array Destructuring
const [first, second] = [1, 2];

// Object Destructuring
const { name, age } = { name: 'John', age: 30 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Destructuring function parameters and return value, also incase you are using some date being returned &lt;code&gt;asynchronously&lt;/code&gt;/&lt;code&gt;API call&lt;/code&gt; make sure to handle the case when the value you are trying to destructure from is &lt;code&gt;undefined&lt;/code&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 doSomething = ({name, age}) =&amp;gt; {
 return {name , age}
}

const {name, age} = doSomething({name: 'John Doe', age: 24})

// Data returned from an API call
const data = getDate()

//Destructuring
const {name, age} = data || {}

//Directly destructuring 
const {name, age} = getData() || {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Spread and Rest operator
&lt;/h2&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1358%2F1%2Ax70lFgXw_qyuVtn1C1nclg.jpeg" 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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1358%2F1%2Ax70lFgXw_qyuVtn1C1nclg.jpeg" alt="Spread and Rest"&gt;&lt;/a&gt;&lt;br&gt;
The spread operator &lt;code&gt;(...)&lt;/code&gt; allows you to spread elements of an &lt;code&gt;array&lt;/code&gt; or &lt;code&gt;object&lt;/code&gt;, while the &lt;code&gt;rest&lt;/code&gt; parameter collects remaining arguments into an &lt;code&gt;array&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Spread Operator
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5];

// Rest Parameter
const sum = (...numbers) =&amp;gt; {
  return numbers.reduce((acc, num) =&amp;gt; acc + num, 0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⭐️ One of the most useful application of the spread operator is while &lt;code&gt;updating&lt;/code&gt;/&lt;code&gt;altering&lt;/code&gt; one value of an &lt;code&gt;object&lt;/code&gt;, retaining all the other values as it is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [obj, setObj] = useState({ name: 'John Doe', location: { city: "Bengaluru", state: "Karnataka" } })

//Update only the city from 'Bengaluru' to 'Mysuru'
setObj(prev =&amp;gt; ({...prev, location: {...prev.location, city: 'Mysuru'}}))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Template Literals
&lt;/h2&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%2Fblog.dmcindoe.dev%2Fimages%2Fjs-template-literals.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%2Fblog.dmcindoe.dev%2Fimages%2Fjs-template-literals.png" alt="Template Literals"&gt;&lt;/a&gt;&lt;br&gt;
Template literals provide a more flexible and readable way to &lt;code&gt;concatenate&lt;/code&gt; strings, including &lt;code&gt;variables&lt;/code&gt; and &lt;code&gt;expressions&lt;/code&gt;. This can be used to declare a &lt;code&gt;multiline&lt;/code&gt; string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = 'World';
console.log(`Hello, ${name}!`);

const description = `My name is ${name}
I am from Bengaluru
I'm stuck in traffic`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are a few tricks that can make your code cleaner, maintainable and easier to write overall. I might have missed out on a few of them, but these are the ones that actually make my life easier on an everyday basis. Happy Coding...&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Top 10 react packages for SaaS platforms</title>
      <dc:creator>Pranav Badami</dc:creator>
      <pubDate>Sat, 04 Nov 2023 10:23:48 +0000</pubDate>
      <link>https://forem.com/fyno/top-10-react-packages-for-saas-platforms-48ea</link>
      <guid>https://forem.com/fyno/top-10-react-packages-for-saas-platforms-48ea</guid>
      <description>&lt;h2&gt;
  
  
  Why Use React Libraries?
&lt;/h2&gt;

&lt;p&gt;When it comes to building a product with React, going it alone can be quite a challenge. While it's not impossible, it's certainly a lot easier—and often wiser—to seek assistance from the vast world of open-source packages. React libraries are like your trusty companions in the development journey, simplifying complex tasks, enhancing functionality, and accelerating your project's progress. In this blog post, we'll explore the top 10 React libraries that can be your go-to resources, making your React development experience more efficient and enjoyable. So, without further ado, let's delve into the world of React libraries.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;a href="https://tanstack.com/query/v3/docs/react/overview" rel="noopener noreferrer"&gt;React-Query&lt;/a&gt; : Your Ultimate Query and Mutation Companion
&lt;/h3&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%2Fdecode.agency%2Fwp-content%2Fuploads%2F2023%2F05%2FReact-Query-logo.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%2Fdecode.agency%2Fwp-content%2Fuploads%2F2023%2F05%2FReact-Query-logo.png" alt="React-Query"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the ever-evolving world of React development, optimizing queries (GET requests) and mutations (POST, PUT, DELETE) can be quite a task. That's where React-Query comes into play, and it's been a game-changer for us. This library simplifies frontend data management with an intuitive implementation using React hooks, offering a plethora of advantages that make it a must-have in your toolkit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy and simplified query management&lt;/li&gt;
&lt;li&gt;Infinite scroll/Pagination for queries&lt;/li&gt;
&lt;li&gt;Effortless Invalidation and Data Refetching&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/pranav_badami/maintaining-query-cache-with-react-query-m3a"&gt;Cache management&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Robust Error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Streamline Form Management with &lt;a href="https://react-hook-form.com/get-started" rel="noopener noreferrer"&gt;React-Hook-Form&lt;/a&gt;
&lt;/h3&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2AFgWMPNlUpjYKhSe7SbOSFQ.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2AFgWMPNlUpjYKhSe7SbOSFQ.png" alt="React-Hook0=-Form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Forms are a cornerstone of web applications, but managing them can often be a daunting task. Dynamic field rendering, state management, and validations can quickly become a maze of complexity. If you've ever found yourself tangled in the web of form-related challenges, React-Hook-Form is here to rescue you. Here is what react-hook-form has to offer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A simple hook which helps you initialise your form and provides all the methods that can be used in the &lt;/li&gt;
&lt;li&gt;FormProvider wrapper with useFormContext hook which can help you manage states for clean and maintainable code.&lt;/li&gt;
&lt;li&gt;useFieldsArray hook allows you to provide a dynamic fields form which allows users to add or remove fields.&lt;/li&gt;
&lt;li&gt;Easy form validation using &lt;a href="https://www.npmjs.com/package/@hookform/resolvers" rel="noopener noreferrer"&gt;yup-resolver&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Unleash Creativity with &lt;a href="https://reactflow.dev/learn" rel="noopener noreferrer"&gt;React-Flow&lt;/a&gt;
&lt;/h3&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%2Fworksolutions.ru%2Fuploads%2F99999999999999999_1_2a116db3f4.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%2Fworksolutions.ru%2Fuploads%2F99999999999999999_1_2a116db3f4.png" alt="React-Flow"&gt;&lt;/a&gt;&lt;br&gt;
In the world of SaaS (Software as a Service), one tool that's invaluable for many is the flow builder. It's a canvas where you design the logic and the flow of your application. Among the numerous libraries out there, React-Flow stands out as a true gem, and it's undoubtedly one of the most enjoyable and creative libraries we've had the pleasure of using. Lets see how we can have some fun with this library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intuitive Flow Building&lt;/li&gt;
&lt;li&gt;Very easy state management for nodes and edges&lt;/li&gt;
&lt;li&gt;Easily create logic to connect nodes and build a drag and drop flow builder&lt;/li&gt;
&lt;li&gt;No limits or hard and fast rule to use this library. Its upto you, to check how crazy you can get with it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4. &lt;a href="https://www.npmjs.com/package/plop" rel="noopener noreferrer"&gt;Plop&lt;/a&gt;: The Micro Generator Framework That Transforms Your Workflow
&lt;/h3&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%2Fplopjs.com%2Fimages%2Fplop-meta-card.jpg" 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%2Fplopjs.com%2Fimages%2Fplop-meta-card.jpg" alt="Plop"&gt;&lt;/a&gt;&lt;br&gt;
While not exclusively a React package, Plop has been an unsung hero in our development toolkit. This micro generator framework may not be a household name, but it's an absolute game-changer when it comes to saving time and streamlining repetitive tasks, it helps with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy and consistent folder structuring in your project.&lt;/li&gt;
&lt;li&gt;Easy files/folder creation with predefined content inside them.&lt;/li&gt;
&lt;li&gt;Simple pattern to make sure uniformity is maintained, especially while working with large teams&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5. &lt;a href="https://www.npmjs.com/package/flat" rel="noopener noreferrer"&gt;Flat&lt;/a&gt;: Mastering Object Flattening and Unflattening with Precision
&lt;/h3&gt;

&lt;p&gt;In the world of application development, handling complex nested objects is a common challenge. Whether you're working with JSON data, configuration files, or any application state, object flattening and unflattening can be a cumbersome task. That's where "Flat" comes to the rescue, offering a consistent and reliable solution for maintaining the structure of your objects without altering their underlying values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides flatten and unflatten functions which flatten a nested object and unflatten it back to the original form.
for example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const nested_object = {
    "name": "Pranav",
    "age": 24,
    "company": "Fyno",
    "address": {
        "city": "Bengaluru",
        "state": "Karnataka",
        "country": "India"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;On using flatten(nested_object) we get&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "Pranav",
    "age": 24,
    "company": "Fyno",
    "address.city": "Bengaluru",
    "address.state": "Karnataka",
    "address.country": "India"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And using unflatten(flattened_object) will give back the original object.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Simplify File Uploads with &lt;a href="https://react-dropzone.js.org/" rel="noopener noreferrer"&gt;React-Dropzone&lt;/a&gt;
&lt;/h3&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%2Fraw.githubusercontent.com%2Freact-dropzone%2Freact-dropzone%2Fmaster%2Flogo%2Flogo.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%2Fraw.githubusercontent.com%2Freact-dropzone%2Freact-dropzone%2Fmaster%2Flogo%2Flogo.png" alt="React-Dropzone"&gt;&lt;/a&gt;&lt;br&gt;
In the age of modern web applications, file uploads have become a routine part of our online experiences. Whether you're building an image-sharing platform, document management system, or any application that involves handling files, React-Dropzone is your answer to seamless file upload functionality. With its simple drag-and-drop interface, it empowers you to achieve remarkable feats. Lets see what we can achieve with this library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple drag and drop zone/area where any file can be dropped to select/upload.&lt;/li&gt;
&lt;li&gt;useDropzone react hook, to easily manage and use all methods provided by the library.&lt;/li&gt;
&lt;li&gt;Defining file types to accept and number of files to accept.&lt;/li&gt;
&lt;li&gt;Custom validation for files, like showing accepted and rejected files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. &lt;a href="https://react-hot-toast.com/" rel="noopener noreferrer"&gt;React-Hot-Toast&lt;/a&gt;: Elevating User Interaction with Alerts and Notifications
&lt;/h3&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%2Frepository-images.githubusercontent.com%2F319456369%2F53412e80-414d-11eb-91d6-b89ae5d419d2" 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%2Frepository-images.githubusercontent.com%2F319456369%2F53412e80-414d-11eb-91d6-b89ae5d419d2" alt="React-hot-toast"&gt;&lt;/a&gt;&lt;br&gt;
In the realm of user-centric applications, timely communication and feedback are essential. React-Hot-Toast has emerged as a personal favourite among developers for delivering real-time alerts, notifications, and in-app reminders, elevating the user experience to new heights. This library offers a powerful yet straightforward way to enhance user engagement through visual communication.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very simple to use&lt;/li&gt;
&lt;li&gt;Easily customisable, you can add many sorts of customisation like delay, ttl (time to live) and many more things.&lt;/li&gt;
&lt;li&gt;Designs for these toasts are very flexible and easy to customise according to product design requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. &lt;a href="https://www.npmjs.com/package/luxon" rel="noopener noreferrer"&gt;Luxon&lt;/a&gt;: Mastering Time and Timezones for Precision Data Handling
&lt;/h3&gt;

&lt;p&gt;In the world of application development, mastering time and timezone management is a fundamental requirement. Many platforms, whether they deal with analytics, activity logs, or any aspect of data that's time-sensitive, need a robust solution for handling time in different formats and working with timezone offsets. Luxon is that solution, offering a powerful toolkit to manage time with precision and confidence. Any sort of data management which is time sensitive would benefit from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comprehensive date and time manipulation&lt;/li&gt;
&lt;li&gt;Timezone support&lt;/li&gt;
&lt;li&gt;Variety of formatting with date and time, as suitable for different use cases&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. Empower Non-Technical Users with &lt;a href="https://react-querybuilder.js.org/docs/intro" rel="noopener noreferrer"&gt;React-Query-Builder&lt;/a&gt;
&lt;/h3&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%2Freact-querybuilder.js.org%2Fimg%2Freact-querybuilder.svg" 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%2Freact-querybuilder.js.org%2Fimg%2Freact-querybuilder.svg" alt="React-Query-Builder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the world of application development, database queries are often a complex and intimidating aspect, particularly for those outside the technical domain. This challenge becomes even more significant in a no-code environment where users are looking for simplicity and empowerment. React-Query-Builder is the answer, simplifying the process of building queries through a user-friendly UI and providing the ability to export in various formats, including JSON, SQL, MongoDB, CEL, and SpEL.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Elevate User Experience with &lt;a href="https://www.npmjs.com/package/use-query-params" rel="noopener noreferrer"&gt;Use-Query-Params&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In the realm of web applications, a seamless user experience often hinges on the ability to maintain and share URLs with filters, search parameters, and other states. Use-Query-Params steps in as an indispensable tool, simplifying the process of encoding and decoding data as query parameters. With the useQueryParam hook, it's easy to achieve the fine balance between URL sharing and an enhanced user experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easily maintainable states with URL&lt;/li&gt;
&lt;li&gt;Any data type can be encoded to the query params&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In our journey at &lt;a href="https://www.fyno.io" rel="noopener noreferrer"&gt;Fyno&lt;/a&gt;, these top 10 React libraries have been invaluable allies, simplifying our development process and addressing the diverse requirements that surface in the world of SaaS platforms. If you haven't already explored the potential of these packages, we encourage you to give them a try. They have the power to streamline your development workflow, enhance user experiences, and make life simpler for you too. So, dive in, experiment, and discover how these libraries can elevate your React projects to new heights. Your next big breakthrough might just be a package away.&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Query - Maintaining Query cache</title>
      <dc:creator>Pranav Badami</dc:creator>
      <pubDate>Fri, 13 Oct 2023 18:16:01 +0000</pubDate>
      <link>https://forem.com/fyno/maintaining-query-cache-with-react-query-m3a</link>
      <guid>https://forem.com/fyno/maintaining-query-cache-with-react-query-m3a</guid>
      <description>&lt;p&gt;React Query has greatly simplified frontend API query handling with improved error management and efficient data caching. However, managing query keys can be challenging, as we discovered at Fyno when dealing with duplicated key names, leading to frustrating hours of debugging. This situation highlights the significance of effective key management. Duplicated keys can lead to data mix-ups and unexpected results. Lets delve into best practices for managing query keys, allowing you to harness React Query's full potential without the hassle of duplicated keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Old Approach
&lt;/h2&gt;

&lt;p&gt;We create a react query hook for each API call and define the query key cache in the react query hook and if we want to invalidate some query then we had to go find the query key and use the same one. Which is a lot of manual work and when you are trying to be as productive as possible, this can cause issues which will be time consuming to debug.&lt;/p&gt;

&lt;p&gt;Some examples of the old approach:&lt;/p&gt;

&lt;p&gt;1 . Simple Query Key&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'

const getTemplates = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetTemplates = () =&amp;gt; {
  return useQuery(['templatesList'],() =&amp;gt; getTemplates())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

const getEvents = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetEvents = () =&amp;gt; {
  return useQuery(['eventsList'],() =&amp;gt; getEvents())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 . Dynamic Query Key&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'

const getTemplateDetails = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetTemplateDetails = (name, version) =&amp;gt; {
  return useQuery(['templateDetails', name, version],() =&amp;gt; getTemplateDetails())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

const getEventDetails = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetEventDetails = (name, version) =&amp;gt; {
  return useQuery(['eventDetails', name, version],() =&amp;gt; getEventDetails())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's deep dive into the problem
&lt;/h2&gt;

&lt;p&gt;Following the best practices, we've been using separate React Query hooks for each API call to the backend. However, each query call requires a unique query key to store the API response data, and as our project has grown with new features, we've encountered some challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Query Key Conundrum:&lt;/strong&gt; One of the dilemmas we faced is deciding what query key to assign to the cache for the response data from an API call. It may seem straightforward at first, but as your project evolves, making this decision can become quite a puzzle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Invalidation and Refetching:&lt;/strong&gt; Figuring out the right query key to invalidate or trigger a refetch based on another API call or a specific action can be like solving a complex puzzle. It's critical to ensure that your data remains up-to-date and accurate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Duplicity Dilemma:&lt;/strong&gt; As we expanded our codebase, we encountered the issue of creating duplicate query keys. This happened when data from various API calls with different responses started to overlap, leading to confusion and unexpected results.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These challenges are not unique, and they can affect the efficiency and maintainability of your project. Lets explore strategies and techniques to tackle these issues head-on, ensuring a smoother development process and a more predictable and reliable application.&lt;/p&gt;




&lt;h2&gt;
  
  
  New Approach
&lt;/h2&gt;

&lt;p&gt;To address these challenges, we took a strategic approach. Firstly, we centralized the creation of all query cache keys for easy accessibility and maintenance. Our goal was to make this process dynamic, allowing customization with specific values while maintaining a standardized approach. &lt;/p&gt;

&lt;h2&gt;
  
  
  Query Keys Factory
&lt;/h2&gt;

&lt;p&gt;Our solution? We call it the "Query Keys Factory." Now, you might wonder why we went with such a name - well, sometimes, cool just sounds cool. It's a nifty little React hook, and its job is simple but incredibly valuable. This hook holds the keys to all the query keys, organized neatly according to the features within our product.&lt;/p&gt;

&lt;p&gt;Create a simple global react hook, you can call it Query Keys Factory to be cool like us.&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 useQueryKeysFactory = () =&amp;gt; {

  //--------Templates-----------&amp;gt; /templates
  const templateKeys = {
    list: ['templatesList'],
    details: (name, version) =&amp;gt; ['templateDetails', name, version]
  }

//--------Events-----------&amp;gt; /events
  const templateKeys = {
    list: ['eventsList'],
    details: (name, version) =&amp;gt; ['eventDetails', name, version]
  }

  return { templateKeys, eventKeys }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code snippet above, we've showcased a straightforward example of a query cache for two API calls of two features, which in this case, are "Templates" and "Events". These API calls include a listing API, providing a list of all the templates/events, and a details API for retrieving information about a single template/event. What makes this approach especially powerful is the encapsulation of these keys within the templateKeys/eventKeys section. These keys serve as the foundation for all query keys related to the /templates and /events endpoint respectively.&lt;/p&gt;

&lt;p&gt;By centralizing these keys in one place, you gain remarkable accessibility and maintainability. You can easily access them from anywhere in your application, making the management of query keys a breeze. To illustrate how it works in practice, let's consider the implementation of a React Query hook for retrieving the list of templates and events. This way, you can see how this approach seamlessly integrates into your development process, offering a cleaner, more organized way to handle query keys throughout your project.&lt;/p&gt;

&lt;p&gt;1 . Simple Query Key&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'

const getTemplates = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetTemplates = () =&amp;gt; {
  const { templateKeys } = useQueryKeysFactory()

  return useQuery(templateKeys['list'],() =&amp;gt; getTemplates())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

const getEvents = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetEvents = () =&amp;gt; {
  const { eventKeys } = useQueryKeysFactory()

  return useQuery(eventKeys['list'],() =&amp;gt; getEvents())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 . Dynamic Query Key&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'

const getTemplateDetails = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetTemplateDetails = (name, version) =&amp;gt; {
  const { templateKeys } = useQueryKeysFactory()

  return useQuery(templateKeys['details'](name, version),() =&amp;gt; getTemplateDetails())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

const getEventDetails = () =&amp;gt; {
 // make your API call here
 return response
}

export const useGetEventDetails = (name, version) =&amp;gt; {
  const { eventKeys } = useQueryKeysFactory()

  return useQuery(eventKeys['details'](name, version),() =&amp;gt; getEventDetails())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's dive into a straightforward yet powerful scenario: invalidating cache based on another API call. We'll walk you through creating a React Query hook for making a delete template/event request. If this deletion operation succeeds, we'll perform an act of cache magic – invalidating the listing API call's cached data. This little trick ensures that our application always fetches the freshest, most up-to-date data from the backend.&lt;/p&gt;

&lt;p&gt;Here's a sneak peek at how it's done:&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'

const deleteTemplate = template_name =&amp;gt; {
  // Add your API call for deleting the template with name template_name
}

export const useDeleteTemplate = () =&amp;gt; {
  const queryClient = useQueryClient()
  const { templateKeys } = useQueryKeysFactory()

  return useMutation(template_name =&amp;gt; deleteTemplate(template_name), {
    onSuccess: () =&amp;gt; {
       queryClient.invalidateQueries(templateKeys['list'])
       }
   })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

const deleteEvent = event_name =&amp;gt; {
  // Add your API call for deleting the template with name event_name
}

export const useDeleteEvent = () =&amp;gt; {
  const queryClient = useQueryClient()
  const { eventKeys } = useQueryKeysFactory()

  return useMutation(event_name =&amp;gt; deleteTemplate(event_name), {
    onSuccess: () =&amp;gt; {
       queryClient.invalidateQueries(eventKeys['list'])
       }
   })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go – query invalidation made simple. No more hunting for query keys, just trust the Query Keys Factory to handle it for you. It's all about efficiency and letting the tools do the work.&lt;/p&gt;

&lt;p&gt;In conclusion, our exploration of managing query keys with React Query has provided valuable insights. We've introduced the Query Keys Factory as a solution to simplify key management, streamline development, and minimize errors. With this approach, you can confidently handle query keys and optimize your development workflow. Mastering React Query's query keys can significantly improve your experience, making your projects more efficient and reliable. Happy coding!&lt;/p&gt;

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