<?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: Cristian Montoya</title>
    <description>The latest articles on DEV Community by Cristian Montoya (@cristianmontoya98).</description>
    <link>https://dev.to/cristianmontoya98</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%2F955626%2F6b9142c3-676f-4693-97f8-0fbcddb8e3d0.png</url>
      <title>DEV Community: Cristian Montoya</title>
      <link>https://dev.to/cristianmontoya98</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cristianmontoya98"/>
    <language>en</language>
    <item>
      <title>How to implement dark mode using Tailwind and React JS?</title>
      <dc:creator>Cristian Montoya</dc:creator>
      <pubDate>Wed, 14 Feb 2024 20:52:08 +0000</pubDate>
      <link>https://dev.to/cristianmontoya98/how-to-implement-dark-mode-using-tailwind-and-react-js-4mmj</link>
      <guid>https://dev.to/cristianmontoya98/how-to-implement-dark-mode-using-tailwind-and-react-js-4mmj</guid>
      <description>&lt;p&gt;Dark mode has become a standard in both mobile and web applications. The sobriety, elegance, and serenity conveyed by dark tones with clear contrasts have led a large number of users to prefer their app to have the option to switch to dark mode.&lt;/p&gt;

&lt;p&gt;The implementation of dark mode in an app built with &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React JS&lt;/a&gt; and &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind&lt;/a&gt; is quite simple. It only requires a couple of configurations in your tailwind.config.js file and building a small logic to detect the theme change from your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Setting up Tailwind&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Open your tailwind.config.js file&lt;br&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%2Fom6ujsek1gutyt3tz08i.png" 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%2Fom6ujsek1gutyt3tz08i.png" alt="imagen del archivo tailwind.config" width="456" height="40"&gt;&lt;/a&gt;&lt;br&gt;
In this file, you will find all the configurations corresponding to Tailwind. Here you will add the following property:&lt;br&gt;
&lt;code&gt;darkMode: 'class'&lt;/code&gt;&lt;br&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%2Fvuj9e03k8ydho028a4pp.png" 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%2Fvuj9e03k8ydho028a4pp.png" alt="imagen del archivo tailwind.config" width="503" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Logic in the button that will toggle the mode&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To perform the mode switch, we will directly access the &lt;a href="https://developer.mozilla.org/es/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;DOM&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use a &lt;em&gt;&lt;a href="https://react.dev/reference/react/useState#usestate" rel="noopener noreferrer"&gt;useState&lt;/a&gt;&lt;/em&gt; which will change when the button is pressed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Definition of useState:
It's defined with the name &lt;em&gt;theme&lt;/em&gt; and its respective modifier &lt;em&gt;setTheme&lt;/em&gt;. It will be of type string and will have the value 'light' by default.
&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%2F2rb6vti93frth2d523t6.png" alt="Imagen de la definición del estado" width="800" height="297"&gt;
&lt;/li&gt;
&lt;li&gt;We define the button that will perform the change:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the button we'll use to change the theme, we'll use the onClick method to call a function that will change the state called &lt;em&gt;changeTheme&lt;/em&gt; &lt;em&gt;(This function can be named as you prefer, for example handleChangeTheme)&lt;/em&gt;&lt;br&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%2Fk9jsai0gakzuwznrlr98.png" 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%2Fk9jsai0gakzuwznrlr98.png" alt="Imagen de la definición del botón " width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function that will execute the change: 
In the &lt;em&gt;changeTheme&lt;/em&gt; function, the value of the state &lt;em&gt;theme&lt;/em&gt; is changed using a condition established by &lt;em&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Operators/Conditional_operator" rel="noopener noreferrer"&gt;the conditional operator&lt;/a&gt;&lt;/em&gt;. If the value of the state is 'light', it will be changed to 'dark', otherwise, the value will be 'light'. This way, we ensure the switch between both values every time the button is clicked.
&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%2Fpfbz8szhhyzae9toenrc.png" alt="Imagen de la función para cambiar el modo" width="800" height="284"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Changing the HTML class with useEffect&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Using the &lt;a href="https://react.dev/reference/react/useEffect" rel="noopener noreferrer"&gt;useEffect&lt;/a&gt; hook, we will add and remove the 'dark' class depending on the content of the &lt;em&gt;theme&lt;/em&gt; state: if the content is 'dark', we will add the 'dark' class to our HTML by accessing the DOM, and if the state value is 'light', we will remove that class from the HTML.
&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%2F67iibaq8ve620l3378sj.png" alt="Imagen del useEffect" width="800" height="325"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Applying the styles for dark mode.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, all we need to do is prefix each style we want to apply to dark mode with the word &lt;em&gt;dark:&lt;/em&gt; Additionally, we'll have the styles already defined in light mode on the element to which we want to apply these styles, like this:&lt;br&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%2Fodp4vesixm337wfxk4yq.png" 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%2Fodp4vesixm337wfxk4yq.png" alt="Implementacion del modo oscuro" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This is the way to implement dark mode in an app built with React JS, however, it can be applied to any modern JS framework.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>react</category>
      <category>tailwindcss</category>
      <category>darkmode</category>
    </item>
    <item>
      <title>¿Cómo implementar modo oscuro usando tailwind y react js?</title>
      <dc:creator>Cristian Montoya</dc:creator>
      <pubDate>Wed, 14 Feb 2024 02:41:18 +0000</pubDate>
      <link>https://dev.to/cristianmontoya98/como-implementar-modo-oscuro-usando-tailwind-y-react-js-4eph</link>
      <guid>https://dev.to/cristianmontoya98/como-implementar-modo-oscuro-usando-tailwind-y-react-js-4eph</guid>
      <description>&lt;p&gt;El modo oscuro se ha convertido en un estándar en las aplicaciones tanto móviles como web, la sobriedad, elegancia y serenidad que transmiten los tonos oscuros con contrastes claros han propiciado que gran parte de los usuarios prefieran que la app que usan cuente con la opción de cambiar el tema a modo oscuro.&lt;/p&gt;

&lt;p&gt;La implementación del tema oscuro en una app construida con react js y &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;tailwind&lt;/a&gt; es bastante sencillo, basta con un par de configuraciones en tu archivo &lt;em&gt;&lt;strong&gt;tailwind.config.js&lt;/strong&gt;&lt;/em&gt; y construir una pequeña lógica para detectar el cambio de tema desde tu aplicación.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Configurando tailwind&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Abre tu archivo tailwind.config.js&lt;br&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%2Fom6ujsek1gutyt3tz08i.png" 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%2Fom6ujsek1gutyt3tz08i.png" alt="imagen del archivo tailwind.config" width="456" height="40"&gt;&lt;/a&gt;&lt;br&gt;
En este archivo encontrarás todas las configuraciones correspondientes a tailwind, aquí agregaras la siguiente propiedad:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;darkMode: 'class'&lt;/code&gt;&lt;br&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%2Fvuj9e03k8ydho028a4pp.png" 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%2Fvuj9e03k8ydho028a4pp.png" alt="imagen del archivo tailwind.config" width="503" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Lógica en el botón que cambiara el modo&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Para realizar el cambio entre modos accederemos directamente al &lt;a href="https://developer.mozilla.org/es/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;DOM&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Usaremos un &lt;em&gt;&lt;a href="https://react.dev/reference/react/useState#usestate" rel="noopener noreferrer"&gt;useState&lt;/a&gt;&lt;/em&gt; que cambiará según se presione el botón. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Definición del useState:
Se define con el nombre &lt;em&gt;theme&lt;/em&gt; y su respectivo modificador &lt;em&gt;setTheme&lt;/em&gt;, este será de tipo string y por defecto va a tener el valor 'light'&lt;/li&gt;
&lt;/ul&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%2F2rb6vti93frth2d523t6.png" 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%2F2rb6vti93frth2d523t6.png" alt="Imagen de la definición del estado" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Definimos el botón que realizará el cambio:
En el botón que usaremos para hacer el cambio de tema usaremos el método onClick para llamar a una función que realizara el cambio del estado llamada &lt;em&gt;changeTheme&lt;/em&gt; &lt;em&gt;(Esta función puede llevar el nombre que prefieras por ejemplo handleChangeTheme)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&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%2Fk9jsai0gakzuwznrlr98.png" 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%2Fk9jsai0gakzuwznrlr98.png" alt="Imagen de la definición del botón " width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Función que ejecutará el cambio:
En la función changeTheme se realiza el cambio del valor del estado &lt;em&gt;theme&lt;/em&gt; por medio de una condición establecida por medio del &lt;em&gt;&lt;a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Operators/Conditional_operator" rel="noopener noreferrer"&gt;operador ternario&lt;/a&gt;&lt;/em&gt;, si el valor del estado es 'light' se cambiará a 'dark', en caso contrario el valor será 'light'. De este modo vamos a garantizar el cambio entre ambos valores cada que se de click en el botón.
&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%2Fpfbz8szhhyzae9toenrc.png" alt="Imagen de la función para cambiar el modo" width="800" height="284"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Cambiando la clase del html con useEffect&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Por medio del hook &lt;a href="https://react.dev/reference/react/useEffect" rel="noopener noreferrer"&gt;useEffect&lt;/a&gt; añadiremos y removeremos la clase ´dark´ dependiendo del contenido del estado &lt;em&gt;&lt;strong&gt;theme&lt;/strong&gt;&lt;/em&gt;: en caso de que el contenido sea 'dark' vamos a añadir la clase dark a nuestro html accediendo al DOM, en el caso de que el valor del estado sea 'light' removeremos dicha clase del html.&lt;/li&gt;
&lt;/ul&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%2F67iibaq8ve620l3378sj.png" 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%2F67iibaq8ve620l3378sj.png" alt="Imagen del useEffect" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Aplicando los estilos del modo oscuro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Ahora lo único que debemos hacer es anteponer la palabra &lt;em&gt;dark:&lt;/em&gt; antes de cada estilo que queremos agregar al modo oscuro además de los estilos que ya tendremos definidos en el modo claro en el elemento al que le queremos aplicar dichos estilos de la siguiente forma:&lt;/p&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%2Fodp4vesixm337wfxk4yq.png" 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%2Fodp4vesixm337wfxk4yq.png" alt="Implementacion del modo oscuro" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusión
&lt;/h2&gt;

&lt;p&gt;Esta es la manera de implementar el modo oscuro en una app realizada con react js, sin embargo puede aplicarse a cualquier framework moderno de js.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>tailwindcss</category>
      <category>español</category>
    </item>
  </channel>
</rss>
