<?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: Safouene Turki</title>
    <description>The latest articles on DEV Community by Safouene Turki (@safouene1).</description>
    <link>https://dev.to/safouene1</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%2F326203%2F3c3ebf13-8a4c-47b3-9114-9fb263c62585.jpg</url>
      <title>DEV Community: Safouene Turki</title>
      <link>https://dev.to/safouene1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/safouene1"/>
    <language>en</language>
    <item>
      <title>Vue js lifecycle hooks for dummies</title>
      <dc:creator>Safouene Turki</dc:creator>
      <pubDate>Mon, 21 Jun 2021 15:29:02 +0000</pubDate>
      <link>https://dev.to/safouene1/vue-js-lifecycle-hooks-for-dummies-5bm8</link>
      <guid>https://dev.to/safouene1/vue-js-lifecycle-hooks-for-dummies-5bm8</guid>
      <description>&lt;h2&gt;
  
  
  What are lifecycle hooks?
&lt;/h2&gt;

&lt;p&gt;Every component in VueJS has a lifecycle which is being managed by Vue itself when it creates the component, mounts the component to the DOM, updates the component and destroy the components. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Il-5PUlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzanx1fsmphhu8arl3ka.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Il-5PUlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzanx1fsmphhu8arl3ka.jpg" alt="Vue js lifcycle"&gt;&lt;/a&gt;&lt;br&gt;
Just like Humans have a lifecycle (birth , growing up , death etc)  We can tap into key moments in that lifecycle by implementing one or more lifecycle hooks giving us the opportunity to add our own code at specific stages of a component lifetime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;for the sake of this article, we will consider a Vue component as a package that will contain HTML / CSS / JS&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jKfzPv0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbkzk1l4x8b547ii3y45.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jKfzPv0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbkzk1l4x8b547ii3y45.jpg" alt="Vue component lifcycle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  - beforeCreate()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jh2DWFim--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mi90oxy6ipnh6v7qtsht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jh2DWFim--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mi90oxy6ipnh6v7qtsht.png" alt="beforeCreate Vuejs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our package is now being filled with events/watchers setups and data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt; Inside this hook, data is still not reactive and events that occur during the component’s lifecycle have not been set up yet.&lt;br&gt;
we can not use any Data/ Methods from the Component, however you can access &lt;a href="https://v3.vuejs.org/guide/component-props.html"&gt;props&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  - Created()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4bosbxqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ih9i96i0gxoswp1yr0s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4bosbxqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ih9i96i0gxoswp1yr0s.png" alt="created vuejs"&gt;&lt;/a&gt;&lt;br&gt;
Our package is finally filled with reactive data , computed properties, methods, watch/event callbacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt;  Data is now reactive and events have been set up You cannot do any DOM manipulations because DOM has not been mounted yet. created() is called earlier in order to trigger actions like &lt;strong&gt;data fetching&lt;/strong&gt; from API backend. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Created will not wait for all of the async operations to complete before moving on to the next stage when making API call.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  - BeforeMount()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YkYuON06--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bal84228rguyafa1mlfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YkYuON06--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bal84228rguyafa1mlfr.png" alt="beforeMount vuejs"&gt;&lt;/a&gt;&lt;br&gt;
the package is on it's way to our depot "The Dom" &lt;br&gt;
&lt;strong&gt;Explanation :&lt;/strong&gt;   the render function is being called for the first time , our template has been compiled and our virtual DOM updated by Vue. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This hook is not called during server-side rendering.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  - Mounted()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rHvjYBWQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de99sjy1dqsq94njj10p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rHvjYBWQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de99sjy1dqsq94njj10p.png" alt="mounted vuejs"&gt;&lt;/a&gt;&lt;br&gt;
the package is now stored in the depot "THE DOM" and have access inside the dom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt; with this hook you can  access or modify the DOM of your component immediately before or after the initial render.&lt;br&gt;
The Vue docs recommend using the mounted() hook over the created() hook for data fetching. &lt;br&gt;
&lt;strong&gt;Vue does not block rendering until the mounted function is done running, so mounted()  runs concurrently with axios .&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This hook is not called during server-side rendering.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  - beforeUpdate()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0sJyOlpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9y3yxyg6gxkxppbzerj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0sJyOlpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9y3yxyg6gxkxppbzerj.jpg" alt="beforeUpdate"&gt;&lt;/a&gt;&lt;br&gt;
the package content is being changed, so it's back to our factory and not accessible to "the DOM" depot anymore. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt; this hook is called when data changes, but the DOM hasn't changed yet. &lt;br&gt;
The Vue Docs recommends using this hook to remove manually added event listeners.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This hook is not called during server-side rendering, because only the initial render is performed server-side.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  - Updated()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KlnPpuPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqlgbddly5puaogpqm7m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KlnPpuPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqlgbddly5puaogpqm7m.jpg" alt="Updated"&gt;&lt;/a&gt;&lt;br&gt;
the package content is back to "the DOM"  depot after the changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt; Updated() is called when there is some data changes that causes the DOM to be re-rendered and patched. This hook is mostly for changes related to the DOM. It is not recommended updating the state with this hook. It's better to  use &lt;a href="https://v3.vuejs.org/api/options-data.html#computed"&gt;computed property&lt;/a&gt; or &lt;a href="https://v3.vuejs.org/api/options-data.html#watch"&gt;Watchers&lt;/a&gt; to react to state changes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This hook is not called during server-side rendering, because only the initial render is performed server-side.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  - unmounted()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x2QfIKkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pkej2yazo31q1re5u50.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x2QfIKkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pkej2yazo31q1re5u50.png" alt="unmounted vuejs"&gt;&lt;/a&gt;&lt;br&gt;
we no longer need the package and it's going straight to the trash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation :&lt;/strong&gt; all directives of the component instance have been destroyed. This is the last step in the component lifecycle, it is similar to death . &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This hook is not called during server-side rendering&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you ever feel lost about Vue JS lifecycle hooks you can have a look at the &lt;a href="https://v3.vuejs.org/guide/instance.html#lifecycle-diagram"&gt;lifecycle diagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why i prefer Tailwind CSS?</title>
      <dc:creator>Safouene Turki</dc:creator>
      <pubDate>Wed, 09 Jun 2021 10:50:12 +0000</pubDate>
      <link>https://dev.to/safouene1/why-i-prefer-tailwind-css-4d68</link>
      <guid>https://dev.to/safouene1/why-i-prefer-tailwind-css-4d68</guid>
      <description>&lt;h2&gt;
  
  
  What is Tailwind CSS ?
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://tailwindcss.com" rel="noopener noreferrer"&gt;the official documentation&lt;/a&gt;, Tailwind CSS is a utility-first CSS framework for rapidly building custom user interfaces.&lt;br&gt;
You can write inline styling and achieve an awesome looking website without writing a single css line ! &lt;/p&gt;
&lt;h2&gt;
  
  
  Tailwind CSS in simple words :
&lt;/h2&gt;

&lt;p&gt;We're able to do all our styling without leaving our HTML, &lt;br&gt;
just by adding &lt;strong&gt;utility classes&lt;/strong&gt;.&lt;br&gt;
Incredible looking interfaces with only few lines of HTML ! &lt;/p&gt;
&lt;h3&gt;
  
  
  What are Utility Classes ?
&lt;/h3&gt;

&lt;p&gt;Utility classes are self-descriptive, single-purpose CSS classes.&lt;br&gt;
they can describe : &lt;br&gt;
Text sizes, colors, and weights&lt;br&gt;
Border colors, widths, and positions&lt;br&gt;
Background colors&lt;br&gt;
Flexbox utilities&lt;br&gt;
Padding and margin helpers&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Utility classes serve as a single one-stop-shop for reusable pieces of code.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Key features of Tailwind  :
&lt;/h3&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%2F4t5iujlncamu58tpw7d4.PNG" 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%2F4t5iujlncamu58tpw7d4.PNG" alt="Tailwind page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No default theme&lt;/li&gt;
&lt;li&gt;No built-in UI components&lt;/li&gt;
&lt;li&gt;No opinion about how your site should look. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;this means it is &lt;strong&gt;highly customizable&lt;/strong&gt;  ! &lt;br&gt;
for example almost every website made with &lt;a href="https://getbootstrap.com" rel="noopener noreferrer"&gt;Boostrap&lt;/a&gt; look almost the same, unless there is some heavy CSS code to change the default styling.&lt;br&gt;
However, that's not the case with Tailwind. &lt;/p&gt;
&lt;h5&gt;
  
  
  Tailwind and HyperColor:
&lt;/h5&gt;

&lt;p&gt;Tailwind comes in with a variety of predefined colors &lt;br&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%2Ffr71pboz4ha3ykesc7xy.PNG" 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%2Ffr71pboz4ha3ykesc7xy.PNG" alt="tailwind colors"&gt;&lt;/a&gt;&lt;br&gt;
which we can easily customize in the "tailwind.config.js" &lt;br&gt;
Gradient Colors with Tailwind are also extremely easy to do.&lt;br&gt;
for example : &lt;br&gt;
&lt;code&gt;bg-gradient-to-r from-pink-500 via-red-500 to-yellow-500&lt;/code&gt;&lt;br&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%2F4u43yyjnyzjbg44p8fsu.PNG" 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%2F4u43yyjnyzjbg44p8fsu.PNG" alt="Tailwind Gradients"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;They even have a  whole website &lt;a href="https://hypercolor.dev" rel="noopener noreferrer"&gt;HyperColor&lt;/a&gt; dedicated to their Color Gradients if you ever got confused ! &lt;/p&gt;
&lt;h4&gt;
  
  
  Tailwind and Hericons :
&lt;/h4&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%2F90k9gu3kzkn70d59duu6.PNG" 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%2F90k9gu3kzkn70d59duu6.PNG" alt="Tailwind Icons"&gt;&lt;/a&gt;&lt;br&gt;
Tailwind comes in with &lt;a href="https://heroicons.com" rel="noopener noreferrer"&gt;Heroicons&lt;/a&gt; a Beautiful hand-crafted set of SVG icons (with both outline and Solid styles). &lt;/p&gt;
&lt;h3&gt;
  
  
  Optimized Production :
&lt;/h3&gt;

&lt;p&gt;Tailwind purge removes all unused CSS and @keyframes . &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of Tailwind like a giant box of LEGO — you dump it all out on the floor and build what you want to build, then when you’re done you put all the pieces you didn’t use back into the box.&lt;br&gt;
Example of how to use tailwind purge  :&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// tailwind.config.js
module.exports = {
  purge: [
    './src/**/*.html',
    './src/**/*.vue',
    './src/**/*.jsx',
  ],
  theme: {},
  variants: {},
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Provide an array of paths to all of your template files using the purge option as shown. &lt;br&gt;
Read the &lt;a href="https://tailwindcss.com/docs/optimizing-for-production" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; for more details. &lt;/p&gt;

&lt;h2&gt;
  
  
  Should you use Tailwind ?
&lt;/h2&gt;

&lt;p&gt;Go with Tailwind if you need a &lt;strong&gt;sleek design&lt;/strong&gt;, a user interface where building with components will be important (because tailwind strongly favors component-based UI). &lt;/p&gt;

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

&lt;p&gt;Building Components with Tailwind focus on the design and the looks of small components and makes them super reusable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;if you want to build micro-components in a elegant way, TailwindCSS is the way to go.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>tailwindcss</category>
      <category>boostrap</category>
      <category>css</category>
      <category>frameworks</category>
    </item>
  </channel>
</rss>
