<?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: Apoorva CG</title>
    <description>The latest articles on DEV Community by Apoorva CG (@apoorvacg).</description>
    <link>https://dev.to/apoorvacg</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%2F877290%2F89a4f0a1-e887-4df6-b049-1e728acac78b.jpg</url>
      <title>DEV Community: Apoorva CG</title>
      <link>https://dev.to/apoorvacg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apoorvacg"/>
    <language>en</language>
    <item>
      <title>There is a simple solution with CSS</title>
      <dc:creator>Apoorva CG</dc:creator>
      <pubDate>Mon, 03 Jul 2023 18:35:23 +0000</pubDate>
      <link>https://dev.to/apoorvacg/there-is-a-simple-solution-with-css-3jlm</link>
      <guid>https://dev.to/apoorvacg/there-is-a-simple-solution-with-css-3jlm</guid>
      <description>&lt;p&gt;Usually CSS is hard! but not this time😄, an answer from Stack Overflow saved me a lot time and unwanted code. The requirement was to show icons onHover of a list item using react.&lt;/p&gt;

&lt;p&gt;Came across this simple and efficient CSS solution without overengineering by &lt;a href="https://stackoverflow.com/users/4758519/arun-khot" rel="noopener noreferrer"&gt;@arunkhot&lt;/a&gt;,&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&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%2Fstackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/53194663/reactjs-render-single-icon-on-hover-for-list-item-rendered-from-array/75562194#75562194" rel="noopener noreferrer"&gt;
            &lt;span class="title-flare"&gt;answer&lt;/span&gt; re: reactjs - Render single icon on hover for list item rendered from array
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Feb 24 '23&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/53194663/reactjs-render-single-icon-on-hover-for-list-item-rendered-from-array/75562194#75562194" rel="noopener noreferrer"&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%2Fstackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          0
        &lt;/div&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%2Fstackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;There is simple solution with CSS
Just add below CSS to the elements you want to show/hide on hover. By default put set CSS property&lt;/p&gt;
&lt;div class="snippet" data-lang="js"&gt;
&lt;div class="snippet-code"&gt;
&lt;pre class="snippet-code-css lang-css prettyprint-override"&gt;&lt;code&gt;{
  display: none
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Element would be visible on mouse hover with below CSS.
&lt;/p&gt;
&lt;div class="snippet" data-lang="js"&gt;
&lt;div class="snippet-code"&gt;
&lt;pre class="snippet-code-css lang-css prettyprint-override"&gt;&lt;code&gt;                '&amp;amp;:hover, &amp;amp;:focus-within': {
                  '.element-class':&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;
&lt;/div&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/53194663/reactjs-render-single-icon-on-hover-for-list-item-rendered-from-array/75562194#75562194" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Answer&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Writing this appreciation post with the time saved😌&lt;/p&gt;

</description>
      <category>stackoverflow</category>
      <category>answers</category>
      <category>css</category>
      <category>react</category>
    </item>
    <item>
      <title>Update your GitHub profile</title>
      <dc:creator>Apoorva CG</dc:creator>
      <pubDate>Tue, 22 Nov 2022 13:30:36 +0000</pubDate>
      <link>https://dev.to/apoorvacg/update-your-github-profile-14fj</link>
      <guid>https://dev.to/apoorvacg/update-your-github-profile-14fj</guid>
      <description>&lt;p&gt;As the developer community is growing, developers are connecting and collaboratively contributing to open-source projects. GitHub is a place where these projects are maintained.&lt;/p&gt;

&lt;p&gt;With this, GitHub also provides a &lt;strong&gt;profile README&lt;/strong&gt; feature, where you can showcase your work, interests, contributions, and other pieces of information on the GitHub profile page. It allows you to be as creative as you want to be, fun and interactive or keep it minimal, as they say '&lt;em&gt;sometimes less is more&lt;/em&gt;' 🎨.&lt;/p&gt;




&lt;p&gt;We are all familiar with the GitHub README markdown files. This file describes or helps in understanding the project. Similarly, we can have one for our profile to share a little bit of information about ourselves with the community.&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%2Fu3agkih826hxym16bm00.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%2Fu3agkih826hxym16bm00.png" alt="GitHub Profile Page" width="800" height="593"&gt;&lt;/a&gt;&lt;/p&gt;
GitHub profile page after adding README file






&lt;h4&gt;
  
  
  To get started,
&lt;/h4&gt;

&lt;p&gt;➡️ Create a &lt;em&gt;repository with your GitHub &lt;strong&gt;username&lt;/strong&gt;&lt;/em&gt; &lt;em&gt;(assuming you have a GitHub &lt;a href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwjiz_y8vL37AhVa2HMBHXEADy4QFnoECA4QAQ&amp;amp;url=https%3A%2F%2Fgithub.com%2Fsignup&amp;amp;usg=AOvVaw0a6qEmIZVdziwPUb-hFApr" rel="noopener noreferrer"&gt;account&lt;/a&gt;)&lt;/em&gt;&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%2F11q13di0qst8v6x00thq.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%2F11q13di0qst8v6x00thq.png" alt="Repo name should be same as your GitHub username" width="735" height="233"&gt;&lt;/a&gt;&lt;/p&gt;
Name the repository same as your GitHub username



&lt;p&gt;&lt;br&gt;&lt;br&gt;
➡️ Don't miss out to &lt;em&gt;initialize a README file&lt;/em&gt; and make it a &lt;em&gt;public repository&lt;/em&gt; (this file should be placed in the root folder). GitHub renders this README at the top of your profile page.&lt;br&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%2Fz7zafznl94s36em3t69t.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%2Fz7zafznl94s36em3t69t.png" alt="Initialize repo with README file" width="721" height="229"&gt;&lt;/a&gt;&lt;/p&gt;
Make a public repository with a README file



&lt;p&gt;&lt;br&gt;&lt;br&gt;
➡️ Once you create this repository, you have a &lt;em&gt;README.md file ready with a basic template&lt;/em&gt; that GitHub provides you to start with. You can now go to your GitHub profile page (&lt;a href="https://github.com/%5BuserName%5D" rel="noopener noreferrer"&gt;https://github.com/[userName]&lt;/a&gt;) to see the changes. Congratulations🎉! you just created a GitHub Profile for yourself👏&lt;/p&gt;




&lt;p&gt;You can go ahead and start editing the README.md file that you just created and add your contents to it. To format the file, make use of GitHub's &lt;em&gt;Flavored Markdown&lt;/em&gt; or use HTML in this Markdown file. You can also add &lt;strong&gt;images&lt;/strong&gt;, &lt;strong&gt;emojis&lt;/strong&gt;, and &lt;strong&gt;GIFs&lt;/strong&gt;, list out recent &lt;strong&gt;blogs&lt;/strong&gt;, gitHub &lt;strong&gt;stats&lt;/strong&gt;, &lt;strong&gt;links&lt;/strong&gt; to connect, interactive UIs and many more to this file. You can preview the changes before committing. Once the commit is made, the changes reflect on your GitHub profile page.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Some useful links&lt;/strong&gt;&lt;/em&gt;,&lt;br&gt;
📝 Markdown syntax and formatting, &lt;a href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/quickstart-for-writing-on-github" rel="noopener noreferrer"&gt;quick start&lt;/a&gt;, &lt;a href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax" rel="noopener noreferrer"&gt;basic writing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📈 Commonly used Endpoints for GitHub stats, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;![Github stats](https://github-readme-stats.vercel.app/api?username=[userName]&amp;amp;theme=gotham)&lt;/code&gt; to display your GitHub account overview. &lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=[userName]&amp;amp;layout=compact)&lt;/code&gt; to list the most frequently used languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can modify your stats with various query parameters available, check out &lt;a href="https://github.com/anuraghazra/github-readme-stats" rel="noopener noreferrer"&gt;this repo&lt;/a&gt; by &lt;a class="mentioned-user" href="https://dev.to/anuraghazra"&gt;@anuraghazra&lt;/a&gt; for more details on customising UI and layouts.&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%2Fwshznzvj07l5hdv8t6rn.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%2Fwshznzvj07l5hdv8t6rn.png" alt="github top lang stats" width="800" height="323"&gt;&lt;/a&gt;GitHub stats for frequency used languages&lt;/p&gt;

&lt;p&gt;😇 To add emojis, check this &lt;a href="https://www.webfx.com/tools/emoji-cheat-sheet/" rel="noopener noreferrer"&gt;emoji-cheat-sheet&lt;/a&gt; for all the codes available.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;🏞 Find any relatable GIFs from &lt;a href="https://giphy.com/" rel="noopener noreferrer"&gt;Giphy&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;📸 You can add images just by dragging and dropping them, or by pasting them directly into the editor which GitHub transforms. You can also use &lt;code&gt;HTML&lt;/code&gt; tags to display images and specify width and height to adjust. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;🌓 Based on themes you can specify different images for light and dark modes with &lt;code&gt;picture&lt;/code&gt; element and &lt;code&gt;prefers-color-scheme&lt;/code&gt; media feature. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👩‍💻 To add social media links or to list the skills, check out this &lt;a href="https://shields.io/" rel="noopener noreferrer"&gt;shields website&lt;/a&gt;. This allows customisation of badges with styles and logos of your choice.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example, &lt;code&gt;&amp;lt;img src="https://img.shields.io/badge/HTML5-red?style=for-the-badge&amp;amp;logo=html5&amp;amp;logoColor=white" alt="html5 Badge"/&amp;gt;&lt;/code&gt;, check the image below to see how the list looks like,&lt;/p&gt;
&lt;/blockquote&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%2Foi2tjsnoenz90womaxu0.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%2Foi2tjsnoenz90womaxu0.png" alt="Social logos" width="800" height="76"&gt;&lt;/a&gt;&lt;br&gt;List of skills added using Shields.io
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;🪄 Display Followers counts and other data using Shields with &lt;a href="https://shields.io/category/social" rel="noopener noreferrer"&gt;social&lt;/a&gt; like &lt;code&gt;https://img.shields.io/github/followers/[userName]?style=social&lt;/code&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;🗂 You can also add a section to list out recent blog posts from any blogging platform to this file, add interactive sections like games by writing scripts with &lt;em&gt;GitHub Workflow and Actions&lt;/em&gt;.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;💻 Need more options, check &lt;a href="https://devicon.dev/" rel="noopener noreferrer"&gt;devicon&lt;/a&gt; for icons representing programming languages, designing, and development tools.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;✨ Customize your profile with any theme of your choice or keep it simple. Check out this repo from &lt;a class="mentioned-user" href="https://dev.to/abhisheknaiidu"&gt;@abhisheknaiidu&lt;/a&gt; -  &lt;a href="https://github.com/abhisheknaiidu/awesome-github-profile-readme" rel="noopener noreferrer"&gt;awesome-github-profile-readme&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We cannot add any &lt;code&gt;CSS&lt;/code&gt; or &lt;code&gt;js&lt;/code&gt; with &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags in this Markdown README file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I would be happy to see some helpful tips or your creative GitHub profiles in the comments below😇, &lt;a href="https://github.com/ApoorvaCG" rel="noopener noreferrer"&gt;here's mine&lt;/a&gt;. Thanks for reading!&lt;/p&gt;

</description>
      <category>github</category>
      <category>profile</category>
      <category>howto</category>
      <category>career</category>
    </item>
    <item>
      <title>React Hook Form with Controllers</title>
      <dc:creator>Apoorva CG</dc:creator>
      <pubDate>Fri, 24 Jun 2022 02:07:51 +0000</pubDate>
      <link>https://dev.to/apoorvacg/react-hook-form-with-controllers-16k3</link>
      <guid>https://dev.to/apoorvacg/react-hook-form-with-controllers-16k3</guid>
      <description>&lt;p&gt;Hi all!👋&lt;/p&gt;

&lt;p&gt;Today here in this post we'll see how we can use Controlled components from react-hook-form( &lt;em&gt;let's call it '&lt;strong&gt;rhf&lt;/strong&gt;'&lt;/em&gt; ) library for building forms. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;rhf&lt;/em&gt; lets us manage form state, handle validations and errors, use controlled components and many more functionalities to our forms react form &lt;em&gt;without useState() hook for handling form values&lt;/em&gt;. Let's go ahead and install &lt;em&gt;rhf&lt;/em&gt; in a CRA-setup project and see how it works,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-hook-form
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&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 react-hook-form
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be integrating &lt;code&gt;material-ui&lt;/code&gt;, &lt;code&gt;react-select&lt;/code&gt; libraries with &lt;em&gt;rhf&lt;/em&gt; form, so let's install these dependencies and get started with it💫&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-select @mui/material @emotion/react @emotion/styled @material-ui/core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be handling errors, dependent input fields, individually reset fields, reset the entire form and finally submit the form.&lt;/p&gt;

&lt;p&gt;Now that we have installed all the dependencies, let's see how can we implement form with &lt;em&gt;rhf&lt;/em&gt;😎. To begin with, we will import &lt;code&gt;useForm&lt;/code&gt; and &lt;code&gt;Controller&lt;/code&gt; from &lt;em&gt;rhf&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useForm()&lt;/code&gt; is a custom hook that, &lt;br&gt;
↪️ takes &lt;em&gt;defaultValues&lt;/em&gt;, &lt;em&gt;mode&lt;/em&gt;, &lt;em&gt;etc.,&lt;/em&gt; as arguments and&lt;br&gt;
↩️ returns &lt;em&gt;formState&lt;/em&gt;, &lt;em&gt;handleSubmit&lt;/em&gt;, &lt;em&gt;watch&lt;/em&gt;, &lt;em&gt;setFocus&lt;/em&gt;, &lt;em&gt;clearErrors&lt;/em&gt; &lt;em&gt;etc.,&lt;/em&gt; as objects and functions to manage forms.&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, Controller } from "react-hook-form";

const defaultValues = {
  name: "",
  email: "abc@xyz.com",
  address: "",
  country: { value: "", label: "" },
  state: { value: "", label: "" }
};

export default function App() {
  const { handleSubmit, reset, control, watch, resetField } = useForm({
    defaultValues
  });
  return(&amp;lt;form&amp;gt;&amp;lt;/form&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Controller&lt;/code&gt; is a wrapper component takes number of props, we will be using&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;name&lt;/code&gt;, unique &amp;amp; required&lt;br&gt;
👉 &lt;code&gt;render&lt;/code&gt;, takes any React components.&lt;br&gt;
👉 &lt;code&gt;rules&lt;/code&gt;, helps to validate fields&lt;br&gt;
👉 &lt;code&gt;control&lt;/code&gt;, registers component to &lt;em&gt;rhf&lt;/em&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;Controller
    name="name"
    control={control}
    rules={{ required: true }}
    render={({ field: { onChange, value }, fieldState: { error 
              } }) =&amp;gt; {
              return (
               &amp;lt;&amp;gt;
                 &amp;lt;TextField
                  placeholderText="Your name goes here!"
                  type="text"
                  name="name"
                  value={value}
                  label="Name"
                  variant="outlined"
                  onChange={onChange}
                  error={error}
                  helperText={error ? "Name is required" : ""}
                 /&amp;gt;
               &amp;lt;/&amp;gt;
              );
         }}
 /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;render&lt;/code&gt; prop attaches events and value into the component. Provides &lt;em&gt;onChange&lt;/em&gt;, &lt;em&gt;onBlur&lt;/em&gt;, &lt;em&gt;name&lt;/em&gt;, &lt;em&gt;ref&lt;/em&gt; and &lt;em&gt;value&lt;/em&gt; to the child component, and also a &lt;em&gt;fieldState&lt;/em&gt; object which contains specific input state to handle input fields element.&lt;/p&gt;

&lt;p&gt;For the same form we will continue by adding &lt;code&gt;react-select&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;      &amp;lt;Controller
        name="country"
        control={control}
        rules={{
          required: true,
          validate: {
            isCountry: (v) =&amp;gt; {
              return v.value !== "" || "Please select country";
            }
          }
        }}
        render={({ field: { onChange, value }, fieldState: { error } }) =&amp;gt; {
          return (
            &amp;lt;&amp;gt;
              &amp;lt;Typography variant="body1"&amp;gt;Country&amp;lt;/Typography&amp;gt;
              &amp;lt;Select
                name="country"
                isClearable
                styles={
                  error &amp;amp;&amp;amp; {
                    control: (provided, state) =&amp;gt; ({
                      ...provided,
                      borderColor: "#fb6340",
                      borderRadius: "0.25rem"
                    }),
                    valueContainer: (provided, state) =&amp;gt; ({
                      ...provided,
                      padding: "8px 8px"
                    })
                  }
                }
                onChange={(selectedOption) =&amp;gt; {
                  resetField("state", {
                    defaultValue: { label: "", value: "" }
                  });
                  onChange(selectedOption);
                }}
                value={{ label: value?.label, value: value?.value }}
                options={countries}
              /&amp;gt;
              {error?.message.length ? (
                &amp;lt;Typography variant="body2" color="#fb6340"&amp;gt;
                  {error.message}
                &amp;lt;/Typography&amp;gt;
              ) : null}
            &amp;lt;/&amp;gt;
          );
        }}
      /&amp;gt;
      &amp;lt;Controller
        name="state"
        control={control}
        rules={{
          required: true,
          validate: {
            isState: (v) =&amp;gt; {
              return v.value !== "" || "Please select state";
            }
          }
        }}
        render={({ field, fieldState: { error } }) =&amp;gt; {
          const countryDetails = watch("country");
          return (
            &amp;lt;&amp;gt;
              &amp;lt;Typography variant="body1"&amp;gt;State&amp;lt;/Typography&amp;gt;
              &amp;lt;Select
                name="state"
                isSearchable
                options={
                  countryDetails?.value.length
                    ? states[countryDetails.value]
                    : []
                }
                placeholder="Select state here"
                {...field}
                styles={
                  error &amp;amp;&amp;amp; {
                    control: (provided, state) =&amp;gt; ({
                      ...provided,
                      borderColor: "#fb6340",
                      borderRadius: "0.25rem"
                    }),
                    valueContainer: (provided, state) =&amp;gt; ({
                      ...provided,
                      padding: "8px 8px"
                    })
                  }
                }
              /&amp;gt;
              {error?.message.length ? (
                &amp;lt;Typography variant="body2" color="#fb6340"&amp;gt;
                  {error.message}
                &amp;lt;/Typography&amp;gt;
              ) : null}
            &amp;lt;/&amp;gt;
          );
        }}
      /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here with &lt;code&gt;resetField&lt;/code&gt;( &lt;em&gt;reset individual fields&lt;/em&gt; ) and &lt;code&gt;watch&lt;/code&gt; ( &lt;em&gt;watch input value by passing the name of it&lt;/em&gt; ) APIs we can manage dependent input fields. &lt;/p&gt;

&lt;p&gt;As you see in the above code, whenever we are changing &lt;em&gt;country&lt;/em&gt; field we reset &lt;em&gt;state&lt;/em&gt; field input values to default. With &lt;code&gt;watch&lt;/code&gt; we can track the &lt;em&gt;country&lt;/em&gt; field and update options for &lt;em&gt;state&lt;/em&gt; field accordingly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Form Validations
&lt;/h4&gt;

&lt;p&gt;To add validations, we are using the &lt;code&gt;rules&lt;/code&gt; prop that provides validation as - &lt;em&gt;required&lt;/em&gt;, &lt;em&gt;min&lt;/em&gt;, &lt;em&gt;max&lt;/em&gt;, &lt;em&gt;minLength&lt;/em&gt;, &lt;em&gt;maxLength&lt;/em&gt;, &lt;em&gt;pattern&lt;/em&gt;, &lt;em&gt;validate&lt;/em&gt;. Any failed validations can be handled with &lt;code&gt;error&lt;/code&gt; from the &lt;code&gt;fieldState&lt;/code&gt; object, easy right❗️❗️&lt;/p&gt;

&lt;h4&gt;
  
  
  Form Submission and Reset
&lt;/h4&gt;

&lt;p&gt;Now wrap these Controller Component in &lt;code&gt;form&lt;/code&gt; element to manage form onSubmit event using &lt;code&gt;handleSubmit&lt;/code&gt; and reset form to default values using &lt;code&gt;reset&lt;/code&gt; functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const { handleSubmit, reset, control, watch, resetField } = useForm({
    defaultValues
  });

  const onResetFormData = () =&amp;gt; {
    reset(defaultValues);
  };
&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;&amp;lt;form onSubmit={handleSubmit((data) =&amp;gt; console.log(data))}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, once we click the submit button, our entered form data will show up in the console.&lt;/p&gt;

&lt;p&gt;You can check out the whole implementation here in &lt;a href="https://codesandbox.io/s/react-hook-form-v7-controller-z4js1o?file=/src/index.js" rel="noopener noreferrer"&gt;codesandbox&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Why do we choose rhf👩‍💻?
&lt;/h4&gt;

&lt;p&gt;Few notable points,&lt;br&gt;
🍬 UI library integrations&lt;br&gt;
🍭 Render optimisation with isolated re-rendering&lt;br&gt;
🥠 Easy Form validations&lt;br&gt;
🍯 Has TypeScript support&lt;br&gt;
🍪 Embraces the hooks API, uncontrolled components&lt;br&gt;
🍫 Minimum Bundle size&lt;/p&gt;

&lt;p&gt;This was one way of implementing forms with react-hook-form. Let me know your thoughts on this😇.&lt;/p&gt;

</description>
      <category>reacthookfrom</category>
      <category>forms</category>
      <category>reactselect</category>
      <category>materialui</category>
    </item>
  </channel>
</rss>
