<?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: Shahzaib</title>
    <description>The latest articles on DEV Community by Shahzaib (@issshahzaib).</description>
    <link>https://dev.to/issshahzaib</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%2F370222%2Fab7cbd4b-3b8a-4b6b-8c67-477c819dd65c.jpg</url>
      <title>DEV Community: Shahzaib</title>
      <link>https://dev.to/issshahzaib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/issshahzaib"/>
    <language>en</language>
    <item>
      <title>The 'Only Use' Hook: Your New Secret Weapon for Conditional React Logic!</title>
      <dc:creator>Shahzaib</dc:creator>
      <pubDate>Fri, 03 Nov 2023 10:18:46 +0000</pubDate>
      <link>https://dev.to/issshahzaib/the-only-use-hook-your-new-secret-weapon-for-conditional-react-logic-3p3m</link>
      <guid>https://dev.to/issshahzaib/the-only-use-hook-your-new-secret-weapon-for-conditional-react-logic-3p3m</guid>
      <description>&lt;p&gt;You might be familiar with &lt;code&gt;React Context&lt;/code&gt; as a global state &amp;amp; an alternative to passing props commonly known as prop drilling. Also you know there's a rule for hooks in React that every hook starts with the word &lt;code&gt;use&lt;/code&gt; like &lt;code&gt;useEffect, useState&lt;/code&gt;. Even every custom hook must start with use.&lt;/p&gt;

&lt;p&gt;A new hook is available on React canary branch which is only named &lt;code&gt;use&lt;/code&gt;. And the most exciting thing about this hook is it can be &lt;em&gt;used conditionally&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;use&lt;/code&gt; is a React Hook that lets you read the value of a resource like a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;Promise&lt;/a&gt; or &lt;a href="https://react.dev/learn/passing-data-deeply-with-context" rel="noopener noreferrer"&gt;context&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are a couple of use-cases where use hook will come handy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accessing a Context even conditionally&lt;/li&gt;
&lt;li&gt;A cleaner way to data fetching in components&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In this post let's have a look at how we can make use for this new hook to access a context conditionally.&lt;/p&gt;

&lt;p&gt;Suppose you've a theme context and one of your component is returning either JSX or nothing on a condition. So, in a case where we're returning nothing from that component, accessing the context will be unnecessary. Due to the constrain that hooks can't be used within a condition, we can't do anything but to access the context first either if we use anything from it or not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a look at the &lt;code&gt;Button&lt;/code&gt; component here which is returning something based on a prop &amp;amp; you can notice that we're accessing the &lt;code&gt;ThemeContext&lt;/code&gt; at top:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/react-usecontext-n5dr9r"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's a have look how this new &lt;code&gt;use&lt;/code&gt; hook can help with this situation.&lt;br&gt;
&lt;code&gt;use&lt;/code&gt; hook allows to access context based on a condition, so we can make use of it to access the &lt;code&gt;ThemeContext&lt;/code&gt; conditionally only when we need it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a look at the &lt;code&gt;Button&lt;/code&gt; component here to see how use hook is being used conditionally: 
&lt;iframe src="https://codesandbox.io/embed/react-use-hook-72cn39"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🌟 Why `env` Wins: Advantages over Objects in Web Development 🚀</title>
      <dc:creator>Shahzaib</dc:creator>
      <pubDate>Wed, 24 May 2023 04:47:35 +0000</pubDate>
      <link>https://dev.to/issshahzaib/why-env-wins-advantages-over-objects-in-web-development-15oc</link>
      <guid>https://dev.to/issshahzaib/why-env-wins-advantages-over-objects-in-web-development-15oc</guid>
      <description>&lt;h2&gt;
  
  
  🌟 Have you ever wondered why to choose env over objects in web development frameworks like React, Angular, Vue, and more? 🤔
&lt;/h2&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%2Fyd0bzng7a6qrojfzyyjg.jpg" 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%2Fyd0bzng7a6qrojfzyyjg.jpg" alt="Web development" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When developing web applications, you might have come across the decision of using &lt;code&gt;env&lt;/code&gt; (environment variables) or objects for managing data. While objects can serve the purpose of data sharing, &lt;code&gt;env&lt;/code&gt; offers distinct advantages that make it a compelling choice in various frameworks.&lt;/p&gt;

&lt;p&gt;🔐 &lt;strong&gt;Enhanced Security with &lt;code&gt;env&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
One of the key benefits of &lt;code&gt;env&lt;/code&gt; is its ability to store sensitive or configuration-specific information securely. Whether it's API keys, database credentials, or other secrets, &lt;code&gt;env&lt;/code&gt; keeps this sensitive data out of the codebase, reducing the risk of exposure. By utilizing &lt;code&gt;env&lt;/code&gt;, you can ensure that your sensitive values are well-protected, enhancing the overall security of your web application.&lt;/p&gt;

&lt;p&gt;🔧 &lt;strong&gt;Configuration Flexibility with &lt;code&gt;env&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;code&gt;env&lt;/code&gt; provides unparalleled configuration flexibility for different environments. You can easily customize the behavior of your application without modifying the source code by changing the values of environment variables. Whether you're deploying your application in development, staging, or production environments, &lt;code&gt;env&lt;/code&gt; allows you to tailor the configuration to each specific environment, making your application highly adaptable.&lt;/p&gt;

&lt;p&gt;🔄 &lt;strong&gt;Consistent Deployment with &lt;code&gt;env&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
By leveraging &lt;code&gt;env&lt;/code&gt;, you can achieve consistent behavior across different deployment environments. Instead of hardcoding values directly into your code, you rely on environment variables that can be set differently depending on the environment. This approach simplifies the deployment process, ensuring that your application behaves consistently regardless of the deployment environment.&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Sharing the Codebase with &lt;code&gt;env&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
When sharing your codebase with others, including an example &lt;code&gt;env&lt;/code&gt; file can greatly streamline the setup process. By adding the original &lt;code&gt;env&lt;/code&gt; file to the &lt;code&gt;.gitignore&lt;/code&gt; file and sharing an example file with the same structure, collaborators can simply add their specific &lt;code&gt;env&lt;/code&gt; values to the file. This saves time and avoids potential configuration issues when setting up the project.&lt;/p&gt;

&lt;p&gt;🚀 &lt;strong&gt;Deployment and Configuration Management&lt;/strong&gt;:&lt;br&gt;
Most deployment platforms support setting &lt;code&gt;env&lt;/code&gt; variables through project deployment settings. This allows for easy modification of variable values without changing the codebase. You can simply adjust the values and redeploy the application, making configuration management more efficient and hassle-free.&lt;/p&gt;

&lt;p&gt;In conclusion, &lt;code&gt;env&lt;/code&gt; is a powerful tool for managing sensitive or configuration-specific data in web development frameworks. Whether you're working with React, Angular, Vue, or other similar frameworks, &lt;code&gt;env&lt;/code&gt; provides enhanced security, configuration flexibility, consistent deployment, streamlined codebase sharing, and efficient deployment and configuration management. By carefully considering the nature and purpose of the data, you can make an informed decision between using &lt;code&gt;env&lt;/code&gt; or objects in your web development projects.&lt;/p&gt;

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