<?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: bilalthepunjabi</title>
    <description>The latest articles on Forem by bilalthepunjabi (@bilalthepunjabi).</description>
    <link>https://forem.com/bilalthepunjabi</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%2F590505%2F8f024471-af7a-4b9b-a0c1-6be509322e69.jpeg</url>
      <title>Forem: bilalthepunjabi</title>
      <link>https://forem.com/bilalthepunjabi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bilalthepunjabi"/>
    <language>en</language>
    <item>
      <title>👨‍💻 Why React Devs Are So Annoyed By Hooks 😠</title>
      <dc:creator>bilalthepunjabi</dc:creator>
      <pubDate>Fri, 31 Mar 2023 21:13:46 +0000</pubDate>
      <link>https://forem.com/bilalthepunjabi/why-react-devs-are-so-annoyed-by-hooks-3hf6</link>
      <guid>https://forem.com/bilalthepunjabi/why-react-devs-are-so-annoyed-by-hooks-3hf6</guid>
      <description>&lt;p&gt;If you're a React developer, you've probably heard of Hooks. They were introduced in React 16.8 and are a way to use state and other React features without writing a class. Sounds great, right? Well, some developers have been less than thrilled with Hooks, and here's why.&lt;/p&gt;

&lt;p&gt;🤔 The Learning Curve&lt;/p&gt;

&lt;p&gt;For starters, Hooks have a bit of a learning curve. Developers who have been working with class components for a long time might find it hard to switch to functional components with Hooks. Plus, there are a lot of Hooks to learn: useState, useEffect, useContext, useRef, useCallback...the list goes on. It can be overwhelming!&lt;/p&gt;

&lt;p&gt;😠 The Breaking Changes&lt;/p&gt;

&lt;p&gt;Another reason why some React developers are annoyed with Hooks is that they can break existing code. For example, if you were using a class component and then switched to a functional component with Hooks, you might have to change your code quite a bit to get it to work. And if you're working on a large codebase, that can be a real headache.&lt;/p&gt;

&lt;p&gt;👀 The Messy Code&lt;/p&gt;

&lt;p&gt;Hooks can also lead to messy code if you're not careful. Because Hooks can be used multiple times within a component, it's easy to end up with a lot of stateful variables and effect calls. And if you're not careful with your naming and organization, your code can quickly become a mess.&lt;/p&gt;

&lt;p&gt;🧐 The Debugging Challenge&lt;/p&gt;

&lt;p&gt;Debugging can also be a challenge with Hooks. Since Hooks are just functions, you can't set breakpoints inside them like you can with class components. This can make it more difficult to figure out what's going on when things go wrong.&lt;/p&gt;

&lt;p&gt;🤖 The Solution&lt;/p&gt;

&lt;p&gt;So, what's the solution? Well, it's not to abandon Hooks altogether. They can be a powerful tool for React developers, and they're not going anywhere. Instead, the key is to use them responsibly and be aware of their potential downsides.&lt;/p&gt;

&lt;p&gt;👨‍💻 Here's an example of using the useState Hook:&lt;br&gt;
&lt;/p&gt;

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

function Example() {
  const [count, setCount] = useState(0);

  function handleClick() {
    setCount(count + 1);
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={handleClick}&amp;gt;
        Click me
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🤖 And there you have it! A brief overview of why some React developers are annoyed by Hooks. Just remember, as with any tool, use them wisely and with caution. And always be ready to adapt and learn new things! 😎&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Typescript gives hard time to vue'ds</title>
      <dc:creator>bilalthepunjabi</dc:creator>
      <pubDate>Fri, 31 Mar 2023 21:08:58 +0000</pubDate>
      <link>https://forem.com/bilalthepunjabi/typescript-gives-hard-time-to-vueds-2ihn</link>
      <guid>https://forem.com/bilalthepunjabi/typescript-gives-hard-time-to-vueds-2ihn</guid>
      <description>&lt;p&gt;👋 Hey there! Are you a Vue.js developer struggling with TypeScript? Well, you're not alone my friend! 😂 It's no secret that TypeScript can give Vue a hard time with its strict typing rules, but fear not, there are ways to make it work seamlessly.&lt;/p&gt;

&lt;p&gt;💡 First off, make sure to take advantage of Vue's built-in TypeScript support. This will give you access to all the type information you need to make your app a success. But let's be honest, sometimes it's just not that simple. 😩&lt;/p&gt;

&lt;p&gt;👨‍💻 One common problem that Vue developers face with TypeScript is the infamous "Property 'x' does not exist on type 'y'" error. You know the one I'm talking about! 😅 But don't worry, there are workarounds for this, such as using the any type or casting your variables to the correct type.&lt;/p&gt;

&lt;p&gt;💻 Another issue you might run into is with Vue's .vue files. TypeScript doesn't play well with them out of the box, but fear not my friends, there are tools like Vetur and Volar that can help you out. 🙌&lt;/p&gt;

&lt;p&gt;🤖 And if all else fails, don't be afraid to reach out to the friendly Vue and TypeScript communities for help. They're always willing to lend a hand and share their experiences. 😊&lt;/p&gt;

&lt;p&gt;So there you have it, TypeScript might give Vue a hard time, but with a little bit of effort and some helpful tools, you can make it work seamlessly. Keep on coding, my friends! 👨‍💻&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Laravel Custom Blade Directive</title>
      <dc:creator>bilalthepunjabi</dc:creator>
      <pubDate>Tue, 31 May 2022 14:01:54 +0000</pubDate>
      <link>https://forem.com/bilalthepunjabi/laravel-custom-blade-directive-1f7g</link>
      <guid>https://forem.com/bilalthepunjabi/laravel-custom-blade-directive-1f7g</guid>
      <description>&lt;p&gt;Hi there folks,&lt;/p&gt;

&lt;p&gt;Today, I would like to talk about the laravel custom blade directives. You would have probably seen @if, @endif which are called directives.&lt;/p&gt;

&lt;p&gt;In this post, I would help you to create your own directives and their limitations and use-cases that will eventually help you to make your application developments much easier.&lt;/p&gt;

&lt;p&gt;We will got through the example directive here. First create a provider with artisan.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:provider BladeServiceProvider&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The path will be &lt;code&gt;app/Providers/BladeServiceProvider&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;?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;

class BladeServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  @print(object)
&lt;/h2&gt;

&lt;p&gt;In the boot function of the provider we have just created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Blade::directive('print', function ($payload) {
     return "&amp;lt;?php 
       echo'&amp;lt;pre&amp;gt;';
       print_r($payload);
       echo'&amp;lt;/pre&amp;gt;'; 
     ?&amp;gt;";
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then use this directive as &lt;code&gt;@print($any_object_or_array)&lt;/code&gt; in any blade template.&lt;br&gt;
If this directive don't work or display then the issue lies with the cache. You have to purge the view cache or you can run &lt;code&gt;php artisan optimize:clear&lt;/code&gt; to purge all cache of any type.&lt;/p&gt;

&lt;p&gt;This is just minimal implementation and use-case of blade-directives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations &amp;amp; Issues
&lt;/h2&gt;

&lt;p&gt;The main issue you will encounter with the results of this custom-directive is of cache. If you don't make these to be dynamic in-nature. Then laravel cache engine nullified your generic-behaviour of your directive.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Blade::directive('{name}', function () { return 'string_expression'})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{string_expression}&lt;/code&gt; is an expression in string form like &lt;br&gt;
&lt;code&gt;"&amp;lt;?php ehco('Hello World'); ?&amp;gt;"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But if you passed something un-proccessed form of code like using another directive or laravel blade-view injection like&lt;br&gt;
&lt;code&gt;return view('blade',compact($var));&lt;/code&gt;.&lt;br&gt;
It conflict with the cache-engine of laravel.&lt;/p&gt;

&lt;p&gt;If you want to render the some blade template on using your directive you can code something like &lt;br&gt;
&lt;code&gt;return "&amp;lt;?php echo view('blade',compact('$model'))-&amp;gt;render(); ?&amp;gt;";&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you have any query or problem that you wanna share then just ping &lt;a class="mentioned-user" href="https://dev.to/bilalthepunjabi"&gt;@bilalthepunjabi&lt;/a&gt; in discussions.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>blade</category>
      <category>custom</category>
    </item>
  </channel>
</rss>
