<?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: Iyadchafroud</title>
    <description>The latest articles on Forem by Iyadchafroud (@iyadchafroud).</description>
    <link>https://forem.com/iyadchafroud</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%2F587783%2F2c1e4932-d530-4f77-840b-97c18df2fc24.png</url>
      <title>Forem: Iyadchafroud</title>
      <link>https://forem.com/iyadchafroud</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/iyadchafroud"/>
    <language>en</language>
    <item>
      <title>why React StrictMode is important ?</title>
      <dc:creator>Iyadchafroud</dc:creator>
      <pubDate>Thu, 09 Feb 2023 21:30:45 +0000</pubDate>
      <link>https://forem.com/iyadchafroud/why-strictmode-is-important--jhg</link>
      <guid>https://forem.com/iyadchafroud/why-strictmode-is-important--jhg</guid>
      <description>&lt;h2&gt;
  
  
  why we need StrictMode in react
&lt;/h2&gt;

&lt;p&gt;In React, it is recommended to write components as **pure functions **because it helps ensure that the component's behavior is predictable and consistent. A pure function is a function that always returns the same output for a given set of inputs, and has no side effects. This makes it easier to test, debug, and reason about the component's behavior.&lt;/p&gt;

&lt;p&gt;StrictMode is used to catch potential problems in your code that may cause unexpected behavior. By enabling StrictMode, React will perform additional checks and warnings on your components, such as re-rendering components or executing Effects an extra time, to help identify issues related to impure rendering or missing Effect cleanup.&lt;/p&gt;

&lt;p&gt;In summary, writing pure components and using StrictMode helps ensure that your components behave as expected, making it easier to develop, test, and maintain your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to implement StrictMode ?
&lt;/h2&gt;



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

function MyComponent() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;My Component&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function App() {
  return (
    &amp;lt;React.StrictMode&amp;gt;
      &amp;lt;MyComponent /&amp;gt;
    &amp;lt;/React.StrictMode&amp;gt;
  );
}

export default App;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  **what strictMode do with component ?
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Enforcing an extra re-render of components to catch any bugs related to impure rendering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Re-executing Effects one additional time to catch bugs related to missing Effect cleanup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performing checks for the usage of deprecated APIs to ensure that your code remains up-to-date.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why Socket.io is better than Web Socket</title>
      <dc:creator>Iyadchafroud</dc:creator>
      <pubDate>Sat, 28 Jan 2023 18:36:47 +0000</pubDate>
      <link>https://forem.com/iyadchafroud/socketio-vs-web-socket-295h</link>
      <guid>https://forem.com/iyadchafroud/socketio-vs-web-socket-295h</guid>
      <description>&lt;p&gt;WebSocket is a** protocol** and Socket.IO is a** library** that uses the &lt;strong&gt;WebSocket protocol&lt;/strong&gt; and provides additional functionality on top of it. So if you don't need any of the additional functionality provided by Socket.IO, it may be more appropriate to use plain WebSockets in your application.&lt;br&gt;
well i will prefer to use socket.io  when i need to :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automatic reconnection&lt;/strong&gt;:&lt;br&gt;
Socket.IO automatically reconnect to the server if the connection is lost, which is very important  for maintaining a stable connection in unreliable network environments but with web socket you need to build this  mecanisme by yourself&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rooms&lt;/strong&gt;: Socket.IO provides a way to organize connections into different  "rooms", which can be useful for building more complex, multi-user applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blockers&lt;/strong&gt;( Proxy ,firewall ,load balancer, antivirus): Socket.io connect automatically with the server even with blockers  but with web socket you need to write many line of code  to deal with  the firewall,the antivirus, the proxy and the load balancer &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Binary support&lt;/strong&gt;: Socket.IO supports binary data in addition to text data but web socket can't handle binary data .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-domain support&lt;/strong&gt;: Socket.IO allows you to connect to a server from a different domain, which can be useful for building cross-domain applications but with web socket you need to use a reverse proxy , CORS headers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fallbacks for older browsers&lt;/strong&gt;: Socket.IO includes fallbacks for older browsers that do not support WebSockets, such as long polling and JSONP polling, which allows you to support a wider range of clients.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>websocket</category>
    </item>
    <item>
      <title>Clear Cache for lunix</title>
      <dc:creator>Iyadchafroud</dc:creator>
      <pubDate>Fri, 20 Jan 2023 08:42:59 +0000</pubDate>
      <link>https://forem.com/iyadchafroud/clear-cache-and-swap-memory-kib</link>
      <guid>https://forem.com/iyadchafroud/clear-cache-and-swap-memory-kib</guid>
      <description>&lt;p&gt;we can use The &lt;strong&gt;free&lt;/strong&gt; command is used to display amount of free and used memory in the system. The command also displays the total amount of swap memory in the system and buffers and caches used by the Linux kernel.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;and to Clear memory  we can use :&lt;br&gt;
To clear &lt;strong&gt;pagecache&lt;/strong&gt; only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sync; echo 1 &amp;gt; /proc/sys/vm/drop_caches

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

&lt;/div&gt;



&lt;p&gt;To clear &lt;strong&gt;dentries&lt;/strong&gt; and &lt;strong&gt;inodes&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sync; echo 2 &amp;gt; /proc/sys/vm/drop_caches

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

&lt;/div&gt;



&lt;p&gt;To clear &lt;strong&gt;pagecache&lt;/strong&gt;, &lt;strong&gt;dentries&lt;/strong&gt; and &lt;strong&gt;inodes&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sync; echo 3 &amp;gt; /proc/sys/vm/drop_caches

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

&lt;/div&gt;



&lt;p&gt;to empty buffer and cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;free &amp;amp;&amp;amp; sync &amp;amp;&amp;amp; echo 3 &amp;gt; /proc/sys/vm/drop_caches &amp;amp;&amp;amp; free
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you has this probleme of permission&lt;br&gt;
&lt;code&gt;bash: /proc/sys/vm/drop_caches: Permission denied&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can use echo piped to sudo tee to allow the proper permission needed when you need to echo as root&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 3 | sudo tee /proc/sys/vm/drop_caches
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>neovim</category>
      <category>opensource</category>
      <category>github</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Error from chokidar :System limit for number of file watchers</title>
      <dc:creator>Iyadchafroud</dc:creator>
      <pubDate>Fri, 13 Jan 2023 16:05:43 +0000</pubDate>
      <link>https://forem.com/iyadchafroud/error-from-chokidar-system-limit-for-number-of-file-watchers-50hj</link>
      <guid>https://forem.com/iyadchafroud/error-from-chokidar-system-limit-for-number-of-file-watchers-50hj</guid>
      <description>&lt;p&gt;In thid post , we will fix System limit for number of file watchers error .&lt;/p&gt;

&lt;p&gt;this error reached  because the number of files &lt;strong&gt;monitored&lt;/strong&gt; by the &lt;strong&gt;system&lt;/strong&gt; has reached its &lt;strong&gt;limit&lt;/strong&gt;.&lt;br&gt;
well linux use &lt;strong&gt;inotify&lt;/strong&gt;  to monitoring filesystem events .&lt;/p&gt;

&lt;p&gt;To  know the current limit of  &lt;strong&gt;max_user_watches&lt;/strong&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;gt; `cat /proc/sys/fs/inotify/max_user_watches`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the current &lt;strong&gt;&lt;em&gt;notify  user instance limit&lt;/em&gt;&lt;/strong&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;gt; `cat /proc/sys/fs/inotify/max_user_instances`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to fix error  you need to increase the number of max user  watches by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; `sudo sysctl fs.inotify.max_user_watches=524288`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and increase the number of maximum number of user instances by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; ` sudo  fs.inotify.max_user_instances = 1024`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>react</category>
    </item>
  </channel>
</rss>
