<?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: William Bojczuk</title>
    <description>The latest articles on Forem by William Bojczuk (@wbojczuk).</description>
    <link>https://forem.com/wbojczuk</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%2F1062613%2Fb0faccc1-277a-484b-8891-5a74b35e7d05.jpg</url>
      <title>Forem: William Bojczuk</title>
      <link>https://forem.com/wbojczuk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wbojczuk"/>
    <language>en</language>
    <item>
      <title>Should you learn Linux shell commands as a web developer in 2023?</title>
      <dc:creator>William Bojczuk</dc:creator>
      <pubDate>Wed, 03 May 2023 15:46:13 +0000</pubDate>
      <link>https://forem.com/wbojczuk/should-you-learn-linux-shell-commands-in-2023-2f3e</link>
      <guid>https://forem.com/wbojczuk/should-you-learn-linux-shell-commands-in-2023-2f3e</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;In this day and age there are nearly an infinite amount of tools that one person or the other is recommending to us as Web Developers.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Of course it would hurt no one to have another skill under their belt, but would it actually be useful?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are definitely a few scenarios where this skill will serve you well. In my experience, this is especially true with PHP which is part of the LAMP stack &lt;em&gt;(Linux Apache MySql PHP)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I know many developers discourage the use of PHP due to the unholy amount of diversity in the language because of it’s old age, and also performance-wise there are better alternatives. ☉ ‿ ⚆&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nJlS6J5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw552s263f7si51vx3eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nJlS6J5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw552s263f7si51vx3eb.png" alt="Image description" width="500" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Regardless of this, PHP is still used by &lt;strong&gt;~78.9%&lt;/strong&gt; of all websites that utilize a server-side language. Thus making PHP still quite a relevant topic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;But why would knowing Linux Shell Commands help with developing in PHP? Can’t I just learn the PHP versions of the commands?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I would argue that understanding what the PHP commands do to the underlying Linux system to achieve your desired result is a very good thing to know.&lt;/p&gt;

&lt;p&gt;Not only because you will get a deeper understanding of commands commonly used in PHP but you’ll also be able to work in the Linux shell effectively when needed.&lt;/p&gt;

&lt;p&gt;The syntax between the commands in PHP and the Linux Shell can be extremely similar. Take the following comparison, both instances achieve the same result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Removing a directory in PHP&lt;/span&gt;
&lt;span class="nb"&gt;rmdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'exampledir'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Removing a directory in the Linux Shell&lt;/span&gt;
&lt;span class="nb"&gt;rmdir &lt;/span&gt;exampledir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  But I don’t use PHP in my workflow… So is this skill useless?
&lt;/h2&gt;

&lt;p&gt;NO, not by a long shot. In fact I recently set up a server/droplet to run NodeJS through Digital Ocean. I had to use Linux Shell Commands to navigate the files, edit files, and start the server’s service, and honestly knowing Shell Commands aided me tons.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Linux powers the majority of servers in the world.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The truth is, most of the services that allow you to host your websites, at the core are Linux. So if you ever need to interact with the underlying OS, knowing the commands to do so will save you quite a bit of time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the end, it really depends if you are going to utilize the skill and if you have time to learn it.&lt;/p&gt;

&lt;p&gt;I personally just completed a course on the subject and find it useful when I need to code in PHP or set up a new droplet. You may not use Linux Shell Commands often, but when you have to, knowledge on the subject will serve you well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;That’s it for this post.&lt;/em&gt;&lt;/strong&gt; I do hope this post helped with your decision of whether or not to learn Linux Shell Commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me know your thoughts and Happy Coding!&lt;/strong&gt; ヽ༼ ຈل͜ຈ༼ ▀̿̿Ĺ̯̿̿▀̿ ̿༽Ɵ͆ل͜Ɵ͆ ༽ﾉ&lt;/p&gt;

&lt;p&gt;Hey, I'm &lt;a href="https://williambojczuk.dev"&gt;William Bojczuk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more tips, tricks and tutorials follow GrowInCode on &lt;a href="https://www.youtube.com/@growincode"&gt;YouTube&lt;/a&gt; or &lt;a href="https://www.instagram.com/growincode/"&gt;Instagram&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How React’s useEffect Hook Changed My Life</title>
      <dc:creator>William Bojczuk</dc:creator>
      <pubDate>Fri, 14 Apr 2023 15:23:18 +0000</pubDate>
      <link>https://forem.com/wbojczuk/how-reacts-useeffect-hook-changed-my-life-3b76</link>
      <guid>https://forem.com/wbojczuk/how-reacts-useeffect-hook-changed-my-life-3b76</guid>
      <description>&lt;p&gt;&lt;em&gt;Oh my God, why can’t my JavaScript find my React Component. WhAt Am I DOiNg WronGGg!!!!?!?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Is probably something every developer starting out with React has said at some point. Luckily the creators of React gave us a hook to combat this.&lt;/p&gt;

&lt;p&gt;Any code that alters a component after the component has been mounted is called a &lt;strong&gt;“side effect”&lt;/strong&gt;. To accomplish this, us developers are left with the &lt;strong&gt;useEffect&lt;/strong&gt; hook.&lt;/p&gt;

&lt;p&gt;In the below example, we are attempting to replace the textContent of a paragraph element with new text. But with this setup, an error will be thrown and no changes will be made. &lt;strong&gt;WHY?&lt;/strong&gt;&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Replace&lt;/span&gt; &lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I’ll tell you why, components in React are still JavaScript objects until they have been mounted/rendered. In this example the statement to change the textContent of the paragraph is actually executed &lt;strong&gt;BEFORE&lt;/strong&gt; the React Component has been returned, much less mounted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;So what can you do to access the component AFTER it’s been rendered to the DOM as HTML?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we come to it, the how. If we update our example to use the useEffect hook to get the job done, then it does what it sounds like, it gets the job done!&lt;/p&gt;

&lt;p&gt;Now keep in mind that you &lt;strong&gt;DO NOT&lt;/strong&gt; put your code directly into the &lt;strong&gt;useEffect&lt;/strong&gt; function’s arguments. &lt;strong&gt;useEffect&lt;/strong&gt; takes a function which is executed upon triggering. The simplest way for me is to pass an anonymous function containing all my JavaScript to the hook like in the example below. But you could include a named function instead.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt; 

  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Replace&lt;/span&gt; &lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Now Guess What?&lt;/strong&gt;&lt;/em&gt; The code works and will now change the textContent of our paragraph to &lt;strong&gt;“New Text”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What about async data????&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If we have a value that we are fetching from an API. We kind of need to update the part of our application that relies on that data once we receive it right? &lt;strong&gt;RIGHT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the below example, I’ve altered our Content component to rely on some data from an API. Using &lt;strong&gt;useEffect&lt;/strong&gt;, we define and use an async function to fetch our data and set the state of our text to the response text.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;contentText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setContentText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Replace This Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://urltoapi.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;setContentText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;textData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; 

  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;contentText&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React does not allow for the function passed to useEffect to be asyncronous. So you have to define it INSIDE of the passed function and execute it there.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;But William, my code runs every single time the component is updated and it’s breaking my code!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, yes it does. This is by design. By default, &lt;strong&gt;useEffect&lt;/strong&gt; is run every time the component needs to update. For those of us that need to limit this like when you’re developing a SPA (single page application) and you need to manually trigger &lt;strong&gt;useEffect&lt;/strong&gt; at a certain time, luckily, again we are saved by the React creators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt; takes a second optional argument. An array of dependency states/values. Whenever one of these state’s values changes is when the &lt;strong&gt;useEffect&lt;/strong&gt; hook is re-triggered. Whether this be on the component updating or any time in between.&lt;/p&gt;

&lt;p&gt;Below I’ve altered our Content component to trigger &lt;strong&gt;useEffect&lt;/strong&gt; every time the &lt;strong&gt;“Trigger useEffect”&lt;/strong&gt; button is clicked, which changes the &lt;strong&gt;triggerCount&lt;/strong&gt; state, and that state is a value in the &lt;strong&gt;useEffect&lt;/strong&gt;’s dependency array.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;triggerCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTriggerCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;setTriggerCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;oldval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;oldval&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`useEffect has been triggered &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;triggerCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; time(s)!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;triggerCount&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Trigger&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;But I only want it to trigger ONCEEE!!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, if you give &lt;strong&gt;useEffect&lt;/strong&gt; an empty array as the dependency array, the hook will only trigger once, and this is when the component has been mounted/rendered. This is because when you provide a dependency array, &lt;strong&gt;useEffect&lt;/strong&gt; waits for one of those values to change before it re-triggers. But if you don’t provide any values, they cannot change, so it will not re-trigger.&lt;/p&gt;

&lt;p&gt;So for those who learn visually, here’s an alteration of the first example where useEffect only triggers once.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt; 

  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Replace&lt;/span&gt; &lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that’s it for this article. I really hope you learned something new and enjoyed it in the process. I did spend a bit of time writing this so if you did enjoy reading it, let me know :D.&lt;/p&gt;

&lt;p&gt;For more tips, tricks and tutorials follow me on &lt;a href="https://www.youtube.com/channel/UCKuVsmlR9mRSAatMjgqhsSQ"&gt;YouTube&lt;/a&gt; or &lt;a href="https://www.instagram.com/growincode/"&gt;Instagram&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The right ways to accept optional parameters in JavaScript.</title>
      <dc:creator>William Bojczuk</dc:creator>
      <pubDate>Tue, 11 Apr 2023 15:42:29 +0000</pubDate>
      <link>https://forem.com/wbojczuk/the-right-ways-to-accept-optional-parameters-in-javascript-3bg</link>
      <guid>https://forem.com/wbojczuk/the-right-ways-to-accept-optional-parameters-in-javascript-3bg</guid>
      <description>&lt;p&gt;If you’ve worked in any coding scripting language, changes are you’ve created a function that takes values from users. But sometimes these values should be optional, for example a parameter that specifies settings for the function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Value Parameters.
&lt;/h2&gt;

&lt;p&gt;Let’s say you have a function that takes two numbers, adds them together and returns the result. The code would look something like this.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addTwoNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We know that calling the function like &lt;code&gt;addTwoNumbers(1, 2);&lt;/code&gt; would result in “3" being returned. But what if we call the function without any parameters like so: &lt;code&gt;addTwoNumbers();&lt;/code&gt; ? Well I’ll tell you, you’ll get “NaN” or “Not a Number”. Let’s say our application requires a numerical value be returned, we can mitigate this error by setting defaults to the parameters. If we alter the function above to look like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addTwoNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then if we call the function without arguments, now the function returns “0” instead of “NaN”. So to put it simply, to set a parameter’s default value, simply add “= val” in the function definition where you accept the parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objects or Arrays.
&lt;/h2&gt;

&lt;p&gt;For some applications, setting a default value for the whole parameter’s value will work. But let’s say we have function that applies a bunch of styles to an element from a parameter named “elemStyles” which is an object like so:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;elementStyles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;elemStyles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}){&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elemStyles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we set up the function like that and then pass &lt;code&gt;{color: “green”}&lt;/code&gt;as the “elemStyles” parameter, then the “backgroundColor” default setting will be removed since the whole "elemStyles" object would be replaced by the passed value.&lt;/p&gt;

&lt;p&gt;We can fix this by altering the function to look like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;elementStyles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;elemStyles&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;elemStyles&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;currentStyles&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentStyles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the default settings for the object are defined in “currentStyles” and any properties set by the user will simply overwrite the default properties.&lt;/p&gt;

&lt;p&gt;Let me know some methods you use for these functions. Happy Coding everyone!&lt;/p&gt;

&lt;p&gt;Thanks for reading! For more tips, tricks and tutorials follow me on &lt;a href="https://www.youtube.com/channel/UCKuVsmlR9mRSAatMjgqhsSQ"&gt;YouTube&lt;/a&gt; or &lt;a href="https://www.instagram.com/growincode"&gt;Instagram&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Make sure and leave a comment if you want to see me cover something specific.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>This is the best way to compress images on a website.</title>
      <dc:creator>William Bojczuk</dc:creator>
      <pubDate>Mon, 10 Apr 2023 19:16:28 +0000</pubDate>
      <link>https://forem.com/wbojczuk/this-is-the-best-way-to-compress-images-on-a-website-4nik</link>
      <guid>https://forem.com/wbojczuk/this-is-the-best-way-to-compress-images-on-a-website-4nik</guid>
      <description>&lt;p&gt;Any website or app that allows users to upload their own photos needs to have a compression system in place. Which one should I use? I tried out different packages so you wouldn’t have to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do you need a compression system?
&lt;/h2&gt;

&lt;p&gt;The real question is, why wouldn’t you? Due to improvements in camera quality comes larger photo sizes. I saw this firsthand in my latest project that allows a user to upload images to their blog. During tests, I realized that from an IPhone 14, photos could easily reach 8 to 11 Megabytes. That’s massive, and too big to be serving to visitors on a website. A compression system can &lt;br&gt;
take your photo and reduce the quality within a certain threshold as well as apply image dimension restraints to save that precious storage.&lt;/p&gt;
&lt;h2&gt;
  
  
  How you can implement this system.
&lt;/h2&gt;

&lt;p&gt;I tried a few different frameworks and came to the conclusion that this one was the easiest to use and provided the desired settings. Image Resize Compress can be installed through NPM if you’re familiar with it &lt;code&gt;npm i image-resize-compress&lt;/code&gt;, or you can simply include the package’s CDN to use the script &lt;code&gt;&amp;lt;script src=”https://cdn.jsdelivr.net/npm/image-resize-compress@1/dist/index.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;. The settings are really straightforward so I wrote up a quick function for you to get started quickly.&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;compressImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;curSettings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;compressRes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fromBlob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;compressRes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c1"&gt;// Using The Function&lt;/span&gt;
&lt;span class="nx"&gt;compressImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;720&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;compressedImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You simply call the function with the input image as the first parameter, and then any settings you want to alter as an object in the second parameter. The default quality is 75, or 75%. the height and width settings are set to auto meaning that the original dimensions will be used, and the default format is &lt;em&gt;&lt;strong&gt;jpg&lt;/strong&gt;&lt;/em&gt; but &lt;em&gt;&lt;strong&gt;webp&lt;/strong&gt;&lt;/em&gt;, &lt;em&gt;&lt;strong&gt;png&lt;/strong&gt;&lt;/em&gt;, &lt;em&gt;&lt;strong&gt;bmp&lt;/strong&gt;&lt;/em&gt;, and _&lt;strong&gt;gif&lt;/strong&gt;_are also available.&lt;/p&gt;

&lt;p&gt;You do have to keep in mind that this function returns a Promise. Which is why I used &lt;code&gt;.then()&lt;/code&gt; to access the resolution (aka the data).&lt;/p&gt;

&lt;p&gt;This package is really easy to use and allows you to not only compress the image but to also resize extremely large images to preset dimensions. If you want to learn more about the package, check out its documentation here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! For more tips, tricks and tutorials follow me on &lt;a href="https://www.youtube.com/@growincode"&gt;YouTube&lt;/a&gt; or &lt;a href="https://www.instagram.com/growincode/"&gt;Instagram&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Make sure and leave a comment if you want to see me cover something specific.&lt;/p&gt;

&lt;p&gt;Thumbnail: &lt;a href="https://freeicons.io/profile/6156"&gt;https://freeicons.io/profile/6156&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
