<?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: Rahman Adewale</title>
    <description>The latest articles on DEV Community by Rahman Adewale (@dwale).</description>
    <link>https://dev.to/dwale</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%2F632706%2F926d7164-48f9-4a04-a96c-6f4167a1de9d.jpeg</url>
      <title>DEV Community: Rahman Adewale</title>
      <link>https://dev.to/dwale</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dwale"/>
    <language>en</language>
    <item>
      <title>React 19 updates you should know</title>
      <dc:creator>Rahman Adewale</dc:creator>
      <pubDate>Sun, 14 Jul 2024 16:38:15 +0000</pubDate>
      <link>https://dev.to/dwale/react-19-updates-you-should-know-2abl</link>
      <guid>https://dev.to/dwale/react-19-updates-you-should-know-2abl</guid>
      <description>&lt;h2&gt;
  
  
  Key React v19 updates
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React Compiler:&lt;/strong&gt; With the addition of the React Compiler we would no longer have to manually manage issues of the unexpected re-rendering of our React applications. The React compiler takes care of this for us by determining where in our the memorization is needed, this leads to a less verbose code since we would no longer need to have hooks like &lt;code&gt;useMemo&lt;/code&gt;, &lt;code&gt;useCallback&lt;/code&gt; and '&lt;code&gt;Memo&lt;/code&gt;' HOC components and it also would help increase the performance of our apps since the compiler would know better where memoization should be added. It takes suit from frameworks like Astro and Svelte.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Actions:&lt;/strong&gt; With Actions, managing forms just became better, we can now get access to the form’s state through hooks like &lt;code&gt;useFormState&lt;/code&gt; or &lt;code&gt;useFormStatus&lt;/code&gt;, with these hooks we can now get access to the error state, loading state and data of the form without too many lines of code. This will be very useful for simple forms. It operates both synchronously and asynchronously &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useOptimistic Hook:&lt;/strong&gt; This is very similar to the optimistic fetching from React query, with this we would be able to pass the UI an expected state through a function while the actual request is still processing. If the request or process fails it reverts to the previous state, if it doesn't, it updates the actual state value. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Document MetaData:&lt;/strong&gt; With the new update, we can now add the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags anywhere in the component tree and we can expect that will be rendered at the top of the file (index.html). This helps remove the need for packages like React Helmet and the &lt;code&gt;useTitle&lt;/code&gt; Hook from react-use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asset Loading:&lt;/strong&gt; The introduction of &lt;code&gt;Suspense&lt;/code&gt; would allow us to decide when a page should be loaded by waiting for certain assets, this would be useful for use when we want to load multi-tenant data before our screen loads, seems like something similar the Angular’s Resolve interface &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Loading:&lt;/strong&gt; We will no longer need to use &lt;code&gt;React.Lazy&lt;/code&gt; to lazy load components, we can now leverage the use of the &lt;code&gt;use&lt;/code&gt; hook from this new update, it performs different functions one of which is lazy loading. It not only lazy loads components, it also lazy loads JS files, promises and even contexts. This hook is slightly more complex and this is just a tiny part of its use cases&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Is DELETE really an idempotent HTTP request?</title>
      <dc:creator>Rahman Adewale</dc:creator>
      <pubDate>Sun, 24 Oct 2021 11:43:37 +0000</pubDate>
      <link>https://dev.to/dwale/is-delete-really-an-idempotent-http-request-3d06</link>
      <guid>https://dev.to/dwale/is-delete-really-an-idempotent-http-request-3d06</guid>
      <description>&lt;p&gt;Idempotency is the ability for an operation to be carried out multiple times without changing the state of the system.&lt;/p&gt;

&lt;p&gt;With this definition we can say regularly used methods like the PUT and GET are idempotent since regardless of what is sent in the request or how many times you make the request the outcome remains the same. Lets take the GET method as an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GET&lt;/span&gt;  &lt;span class="nx"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//api-resource/api/v1/getData&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No matter how many times the endpoint is called, it will always result in the same outcome, the system remains unchanged.&lt;/p&gt;

&lt;p&gt;Now lets answer the question &lt;strong&gt;why is the DELETE method idempotent?&lt;/strong&gt; Deleting the item from the first call removes the item from the system and subsequent request will return a 404 since the resource has been deleted.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The key here is to understand that idempotency doesn't mean the response will always be the same, it means that the state of the system will remain unchanged.&lt;/em&gt; Lets use this delete request as an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;DELETE&lt;/span&gt;  &lt;span class="nx"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//api-resource/api/v1/delete/1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the data with id of 1 has been deleted on the first request, making this request multiple times won't change anything on the system meaning it would always result to the thing, the data with an id of 1 no longer exists.&lt;/p&gt;

&lt;p&gt;Extra: The PUT also does the same since making the same call with the same request body would result to the same data being overwritten. Hence nothing changed.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Angular directives: Interesting ways to use it.</title>
      <dc:creator>Rahman Adewale</dc:creator>
      <pubDate>Wed, 19 May 2021 22:04:40 +0000</pubDate>
      <link>https://dev.to/dwale/angular-directives-interesting-ways-to-use-it-1k4b</link>
      <guid>https://dev.to/dwale/angular-directives-interesting-ways-to-use-it-1k4b</guid>
      <description>&lt;p&gt;This article will be using the angular directive to create a reusable custom user validation field. A typical use case will be an account lookup field or any user validation field.&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%2Fdp7a4smvh4wgumcddaoo.gif" 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%2Fdp7a4smvh4wgumcddaoo.gif" alt="gif for validate account"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll be using a bank account validation feature for this document. I came about this idea due to my experience in the fintech industry, where I've had to implement this across various applications, this will allow you to keep your code DRY and it also looks cool 😉.&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" [appAccountLookup] = "bankInformationForm.value"&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;First, we create our angular application using the Angular CLI&lt;/p&gt;

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

ng new account-validation


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

&lt;/div&gt;

&lt;p&gt;Once that's done, we need to navigate into our application and create our directive, it should be added automatically to your declarations array in your app.module.ts file. You can achieve that with the following command.&lt;/p&gt;

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

cd account-validation
ng generate directive accountLookup


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

&lt;/div&gt;

&lt;p&gt;Now in our app folder, let's create an interface that will help define the signature of the object our directive will accept as an input. It should look like this.&lt;/p&gt;

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

**bankInfo.ts**

export class IBankInfo {
   bankCode: string;
   bankAccountNumber: string;
};



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

&lt;/div&gt;

&lt;p&gt;Our newly created directive should have the structure displayed below&lt;/p&gt;

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

** account-lookup.directive.ts **

import { Directive } from '@angular/core';

@Directive({
selector: '[appAccountLookup]'
})

export class AccountLookupDirective {
constructor() {}
}


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

&lt;/div&gt;

&lt;p&gt;Before we continue with our directive, let's create the form that will house the input that will use the directive. It should look like this once you are done.&lt;/p&gt;

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

**app.component.ts**

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  bankInformationForm!: FormGroup;

  constructor (private formBuilder: FormBuilder) {}
  ngOnInit(): void {
     this.initializeForm();
  }

  private initializeForm():void {
   this.bankInformationForm = this.formBuilder.group({
      bankCode: ["", Validators.required],
      bankAccountNumber: ["", Validators.required]
  });
 }
}


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

&lt;/div&gt;

&lt;p&gt;Next up, let's bind our template to the form and use our directive in the account number input field&lt;/p&gt;

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

**app.component.html**

&amp;lt;form  [formGroup]= "bankInformationForm"&amp;gt;
  &amp;lt;fieldset&amp;gt;
    &amp;lt;div class="input__field--row"&amp;gt;
      &amp;lt;label &amp;gt;Bank&amp;lt;/label&amp;gt;
      &amp;lt;span class="input__wrapper"&amp;gt;
       &amp;lt;select name="bankCode" id="bankCode" formControlName="bankCode"&amp;gt;
   &amp;lt;option [disabled]=true value=""&amp;gt;Choose Bank&amp;lt;/option&amp;gt;
   &amp;lt;option value="038"&amp;gt;GTBank&amp;lt;/option&amp;gt;
       &amp;lt;/select&amp;gt;
      &amp;lt;/span&amp;gt;
     &amp;lt;/div&amp;gt;

    &amp;lt;div class="input__field--row"&amp;gt;
      &amp;lt;label&amp;gt;Account Number&amp;lt;/label&amp;gt;
      &amp;lt;span class="input__wrapper"&amp;gt;
       &amp;lt;input type="text" name="bankAccountNumber"id="bankAccountNumber" formControlName="bankAccountNumber" [appAccountLookup] = "bankInformationForm.value"/&amp;gt;
      &amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/fieldset&amp;gt; 
&amp;lt;/form&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;Now, let's bring in all the elements we need to bring this directive to life.&lt;/p&gt;

&lt;p&gt;Our directive will accept the bank details we retrieve from our BankInformation form. We will be making use of reactive forms so don't forget to import the ReactiveFormsModule in your app.module.ts file, we will need to import the &lt;a href="https://angular.io/api/core/Input" rel="noopener noreferrer"&gt;Input&lt;/a&gt; decorator. We are also going to need the &lt;a href="https://angular.io/api/core/Renderer2" rel="noopener noreferrer"&gt;Renderer2&lt;/a&gt; and &lt;a href="https://angular.io/api/core/ElementRef" rel="noopener noreferrer"&gt;ElementRef&lt;/a&gt; classes to be injected in here to make this work, now your directive should look like this.&lt;br&gt;
It will take the &lt;strong&gt;bankDetails&lt;/strong&gt; object as its Input so we can declare it as it is below. We would also be adding a loading text and a default text to the element that will perform the action.&lt;/p&gt;

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

** account-lookup.directive.ts **
import { Directive, ElementRef, Input, Renderer2} from '@angular/core';
@Directive({
  selector: '[appAccountLookup]'
})
export class AccountLookupDirective {
 @Input('appAccountLookup') bankDetails!: IBankInfo;
 defaultActionText: string = 'Verify Account';
 loadingActionText: string = 'Verifying...';

  constructor(private renderer: Renderer2, private el: ElementRef)                                                    {}
}


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

&lt;/div&gt;

&lt;p&gt;Great! next up, let's code the method that will modify our input by adding the necessary elements to it which will be called in the constructor of our AccountLookupDirective class.&lt;/p&gt;

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

private modifyField():void {

  // Set style of parent
  const parent =  this.renderer.parentNode(this.el.nativeElement)
  this.renderer.setStyle(parent, 'position', 'relative');

  // Create action element inside the input field
  const actionButton = this.renderer.createElement('span');
  this.renderer.addClass(actionButton, 'inside__input--button');
this.renderer.setProperty(actionButton,'innerHTML',this.defaultActionText);

  actionButton.addEventListener('click', (event:any) =&amp;gt; {
  // Method that will return the account name
  });

  this.renderer.appendChild(parent, actionButton);
  };


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

&lt;/div&gt;

&lt;p&gt;In the snippet above we've created the &lt;em&gt;"Verify"&lt;/em&gt; action, we also gave it a class of &lt;em&gt;"inside__input - button"&lt;/em&gt;, the CSS class will be styled like this. Let's also add the class our account name will be displayed, &lt;em&gt;"result__under - text"&lt;/em&gt;.&lt;/p&gt;

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

.inside__input--button {
   position: absolute;
   font-size: 10px;
   right: 13px;
   top:30%;
   cursor: pointer;
   user-select: none;
 }
.result__under--text {
   position: absolute;
   font-size: 12px;
   left: 0px;
   bottom: -50%;
   cursor: pointer;
   user-select: none;
}


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

&lt;/div&gt;

&lt;p&gt;What we just did above was to add a verify button inside our input element so our users can click on that button and fetch the account name from the account validation API.&lt;/p&gt;

&lt;p&gt;Let's create a utility service that will contain the method which will make the API call to the service to validate the user's bank details.&lt;/p&gt;

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

ng generate service utility


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

&lt;/div&gt;

&lt;p&gt;Now let's add the method that will make the API call, your service should look like this.&lt;/p&gt;

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

**utility.service.ts**
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
  providedIn: 'root'
})
export class UtilityService {
  constructor( private httpClient: HttpClient ) { }

  public validateAccount(validateAccount): Observable&amp;lt;any&amp;gt; {

    return this.httpClient.post('this.apis.verifyAccount', validateAccount)
  }
}


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

&lt;/div&gt;

&lt;p&gt;Now import the service in our directive and inject it via the constructor&lt;/p&gt;

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

** app.component.ts **
import { IBankInfo } from './bankInfo';
import { UtilityService } from './utility-service.service';


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

&lt;/div&gt;

&lt;p&gt;Now let's code the method that will make this API call and the actions that will be performed after the account name is returned. We will call this method &lt;strong&gt;verifyAccountDetails&lt;/strong&gt;. This is where we retrieve the account name and append it to the input field.&lt;/p&gt;

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

**account-lookup.directive.ts**

  private verifyAccountDetails(actionButton: HTMLElement,  parent:HTMLElement){
this.renderer.setProperty(actionButton,'innerHTML',this.loadingActionText);

  const accountNameDisplay = this.renderer.createElement('span');
  this.renderer.addClass(accountNameDisplay, 'result__under--text');

  this.renderer.appendChild(parent, accountNameDisplay);

 this.utilityService.validateAccount(this.bankDetails)
 .subscribe((resp)=&amp;gt; {
   actionButton.innerHTML = this.defaultActionText;
this.renderer.setProperty(accountNameDisplay,'innerHTML',resp.accountName);
},
 (error: any)=&amp;gt; {
   actionButton.innerHTML = this.defaultActionText;
   console.log(error);
  })
 }


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

&lt;/div&gt;

&lt;p&gt;In the above snippet, our method accepts the actionButton and the parent element as compulsory parameters. We created the element the returned account name will be displayed and gave a class of &lt;em&gt;result_under - text&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With that, we can easily reuse this directive in any component across our application. You can find the code on my &lt;a href="https://github.com/dwale/account-lookup-directive-in-angular" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, please leave your comments and suggestions.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>directives</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
