<?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: Ahmet Karakuş</title>
    <description>The latest articles on DEV Community by Ahmet Karakuş (@ahmetkarakus).</description>
    <link>https://dev.to/ahmetkarakus</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%2F2305851%2F33223f71-15eb-4a71-9b2f-bcab241a1628.png</url>
      <title>DEV Community: Ahmet Karakuş</title>
      <link>https://dev.to/ahmetkarakus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmetkarakus"/>
    <language>en</language>
    <item>
      <title>React Hook Form with MUI: TypeScript-Supported Generic Form Components</title>
      <dc:creator>Ahmet Karakuş</dc:creator>
      <pubDate>Wed, 30 Oct 2024 19:45:49 +0000</pubDate>
      <link>https://dev.to/ahmetkarakus/react-hook-form-with-mui-typescript-supported-generic-form-components-4heh</link>
      <guid>https://dev.to/ahmetkarakus/react-hook-form-with-mui-typescript-supported-generic-form-components-4heh</guid>
      <description>&lt;p&gt;In my projects, I often prefer using the trio of MUI, RHF, and ZOD/YUP. Why, you ask? Because there’s something appealing about starting a new project every other day and never looking at it again.&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%2F8rm7t2y9i98hx3zt9vqm.gif" 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%2F8rm7t2y9i98hx3zt9vqm.gif" alt="Image description" width="480" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, when kicking off a new project, here are my steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I pick the colors that match my mood that day&lt;/li&gt;
&lt;li&gt;set up my theme with MUI&lt;/li&gt;
&lt;li&gt;and voilà… I start managing my form processes with RHF and ZOD. (Of course, after setting up the usual suspects like the router and other basics).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, I’ve noticed that when using RHF — especially with the Controller— the code tends to get lengthy. For instance, let’s look at this Autocomplete code block:&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%2F045zq3id5aoswvcxct7d.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%2F045zq3id5aoswvcxct7d.png" alt="Image description" width="800" height="815"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just to display a few cities in a fancy searchable dropdown, we ended up writing 29 lines of code. To avoid having to revisit code that slows down my flow, I created RHF-compatible form components with TypeScript-supported generic types. Now, let’s take a look at the above Autocomplete component again with this approach:&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%2Fjv0ut8lpf96i89okb8kj.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%2Fjv0ut8lpf96i89okb8kj.png" alt="Image description" width="556" height="580"&gt;&lt;/a&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%2Fmcmnk7w60vv9hpu185tc.gif" 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%2Fmcmnk7w60vv9hpu185tc.gif" alt="Image description" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If, like me, reducing the number of lines of code makes you forget about life’s problems, future worries, and state issues, you can explore all these form components from &lt;a href="https://github.com/ahmetkarakus0/mui-easy-hook-form" rel="noopener noreferrer"&gt;this github repo&lt;/a&gt;. Here is the list of the components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Autocomplete / MultiAutocomplete&lt;/li&gt;
&lt;li&gt;Checkbox&lt;/li&gt;
&lt;li&gt;DatePicker / DateTimePicker&lt;/li&gt;
&lt;li&gt;Radio&lt;/li&gt;
&lt;li&gt;Select&lt;/li&gt;
&lt;li&gt;Slider&lt;/li&gt;
&lt;li&gt;Switch&lt;/li&gt;
&lt;li&gt;TextField&lt;/li&gt;
&lt;li&gt;Form&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding…&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>mui</category>
      <category>reacthookform</category>
    </item>
  </channel>
</rss>
