<?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: Agustín</title>
    <description>The latest articles on DEV Community by Agustín (@agustito37).</description>
    <link>https://dev.to/agustito37</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%2F427313%2F4891b5ac-cdfe-4aa6-ba99-f46fffd666f2.jpeg</url>
      <title>DEV Community: Agustín</title>
      <link>https://dev.to/agustito37</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/agustito37"/>
    <language>en</language>
    <item>
      <title>Cómo manejar estilos en React Native con nuestro hook useStyles</title>
      <dc:creator>Agustín</dc:creator>
      <pubDate>Wed, 25 Nov 2020 14:09:03 +0000</pubDate>
      <link>https://dev.to/rootstrap/como-manejar-estilos-con-nuestro-hook-usestyles-1o0p</link>
      <guid>https://dev.to/rootstrap/como-manejar-estilos-con-nuestro-hook-usestyles-1o0p</guid>
      <description>&lt;p&gt;¿Alguno tiene una idea clara de cómo manejar estilos en React Native? Yo no.&lt;/p&gt;

&lt;p&gt;Hace unos años que trabajo con este framework y nunca pude conseguir una forma concisa de utilizar estilos. En este último año he intentado con algunas librerías con conceptos innovadores como Styled Components, las cuales no me han convencido por completo. Como resultado de esta insatisfacción con las actuales alternativas se creó la librería useStyles.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Qué es useStyles y cómo puede ayudarme?
&lt;/h2&gt;

&lt;p&gt;Organizar los estilos en React Native puede ser complicado, un dolor de cabeza si no aplicas buenas práctias de programación. useStyles viene con la idea de alivianar dicha carga brindando las herramientas para que puedas generar aplicaciones donde los estilos tengan su propio lugar y puedan residir de forma armónica con los componentes.&lt;/p&gt;

&lt;p&gt;Si resumimos qué hace useStyles: es un hook, el cual te permite consumir de forma sencilla, limpia y eficiente los estilos de tu aplicación. Por lo que si te atrae la idea de mejorar la forma en que escribes tus estilos y así generar aplicaciones más limpias, te invito a que pases por el &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repositorio&lt;/a&gt; y lo pruebes por ti mismo.&lt;/p&gt;

&lt;p&gt;A continuación veremos un ejemplo de uso.&lt;/p&gt;

&lt;h2&gt;
  
  
  Uso
&lt;/h2&gt;

&lt;p&gt;El siguiente ejemplo muestra cómo aplicaríamos estilos de forma nativa para generar un simple container con un texto dentro.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Visto de esta forma, no parece un mal código, ¿verdad? Ahora qué pasa cuando el componente empieza a crecer.&lt;/p&gt;

&lt;p&gt;El componente unas semanas después, unas muy malas semanas después:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Como verán, nuestro lindo componente empezó a ser devorado lentamente por nuestros feos estilos. Si bien hay muchas formas de mejorar este código, dado que React Native no tiene una forma clara y sencilla de manejar estilos, estas malas prácticas se vuelven algo común.&lt;/p&gt;

&lt;p&gt;Ahora implementemos lo mismo pero con useStyles:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Perdonen 😢. Mis ojos se llenaron de alegría al ver el código organizado. Sniff. Capaz esto les hace acordar un poco al uso de CSS. Si bien useStyles está inspirado en el uso de clases CSS, esta es una solución creada especialmente para React Native; poco tiene que ver con CSS.&lt;/p&gt;

&lt;p&gt;Volviendo al previo ejemplo, se puede ver cómo el hook &lt;code&gt;useStyles&lt;/code&gt; devuelve una función, que es utilizada luego para consumir nuestros estilos. Ya habrán notado algunas declaraciones peculiares, como un hook al que se le pasan dependencias, y algunos prefijos como &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;$&lt;/code&gt; y &lt;code&gt;:&lt;/code&gt;. A continuación, cuando veamos la definición de los estilos, vamos a ver qué significan.&lt;/p&gt;

&lt;p&gt;useStyles te provee las funciones &lt;code&gt;GlobalStyles&lt;/code&gt; y &lt;code&gt;Styles&lt;/code&gt; para definir estilos globales y locales.&lt;/p&gt;

&lt;p&gt;Estilos globales:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Estilos del componente:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;La idea no es analizar en detalle cada una de las funcionalidades, para eso pueden chequear el &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repositorio&lt;/a&gt;. Pero en forma resumida se pueden explicar de la siguiente manera:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Constantes (&lt;code&gt;$&lt;/code&gt;): podemos reutilizarlas en otros estilos y componentes.&lt;/li&gt;
&lt;li&gt;Estilos estáticos (&lt;code&gt;.&lt;/code&gt;): estilos regulares que pueden ser reutilizados en otros estilos y componentes.&lt;/li&gt;
&lt;li&gt;Estilos computados (&lt;code&gt;&amp;amp;&lt;/code&gt;): estilos que dependen de ciertas dependencias pasadas en el hook. Si alguna dependencia cambia, estos estilos son re-computados.&lt;/li&gt;
&lt;li&gt;Paths (&lt;code&gt;:&lt;/code&gt;): abreviaciones de los estilos. Por ejemplo: para definir la propiedad &lt;code&gt;backgroundColor: 'red'&lt;/code&gt; se puede utilizar el path &lt;code&gt;bg:color:red&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resumen
&lt;/h2&gt;

&lt;p&gt;useStyles es una librería creada con la finalidad de solucionar un problema recurrente que solemos tener los desarrolladores en React Native: estilos desorganizados e invasivos en nuestros componentes. Con useStyles utilizamos un hook para consumir los estilos, el cual nos da una interfaz sencilla, limpia y eficiente.&lt;/p&gt;

&lt;p&gt;Te invito a chequear el &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repositorio&lt;/a&gt; para ver qué más puedes hacer con useStyles y compruebes que esta librería realmente te facilitará tu trabajo como desarrollador. Por supuesto, cualquier contribución es bienvenida.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lea este artículo y más contenido en el blog de Rootstrap: &lt;a href="https://www.rootstrap.com/blog"&gt;https://www.rootstrap.com/blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href="https://www.rootstrap.com/blog/usestyles-react-native-styles-hook/"&gt;https://www.rootstrap.com/blog/usestyles-react-native-styles-hook/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;https://github.com/rootstrap/react-native-use-styles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[3] &lt;a href="https://styled-components.com/"&gt;https://styled-components.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>styles</category>
      <category>translated</category>
      <category>spanish</category>
    </item>
    <item>
      <title>How to manage styles in React Native with our useStyles hook</title>
      <dc:creator>Agustín</dc:creator>
      <pubDate>Wed, 25 Nov 2020 13:48:53 +0000</pubDate>
      <link>https://dev.to/rootstrap/how-to-manage-styles-in-react-native-with-our-usestyles-hook-4fc6</link>
      <guid>https://dev.to/rootstrap/how-to-manage-styles-in-react-native-with-our-usestyles-hook-4fc6</guid>
      <description>&lt;p&gt;Does anyone know how to properly manage styles in React Native? I don't.&lt;/p&gt;

&lt;p&gt;I have been working with this framework for a couple of years now and couldn't get a concise way of using styles. This last year I've tried some libraries with novel concepts as Styled Components, but I couldn't get used to them. As a result of this dissatisfaction with the current alternatives, useStyles was born.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is useStyles and how can it help me?
&lt;/h2&gt;

&lt;p&gt;Organizing styles in React Native can be tricky, a headache if you don't apply good programming practices. useStyles comes with the purpose of ​​alleviating this burden by providing the tools so that you can generate applications where the styles have their own place and can reside harmoniously with the components.&lt;/p&gt;

&lt;p&gt;If we summarize what useStyles does: it is a hook, which allows you to consume the styles of your application in a simple, clean, and efficient way. So if the idea of ​​improving the way you write your styles and generating cleaner applications is appealing, I invite you to visit the &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repository&lt;/a&gt; and try it out for yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;The following example shows how we would apply styles natively to generate a simple container with text inside.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Seen this way, it doesn't look like bad code, does it? Now, what happens when the component starts to grow.&lt;/p&gt;

&lt;p&gt;The component a few weeks later, a few very rough weeks later:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, our clean component began to be slowly eaten by our ugly styles. While there are many ways to improve this code, since React Native does not have a clear and simple way to handle styles, these bad practices get pretty common.&lt;/p&gt;

&lt;p&gt;Now let's implement the same but with useStyles:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Excuse me 😢. My eyes were filled with joy when I saw this organized code. Sniff. Maybe this reminds you a little bit of CSS styles. Although useStyles is inspired by CSS classes, this is a solution created especially for React Native; it has little to do with how CSS works.&lt;/p&gt;

&lt;p&gt;Going back to the previous example, you can see how the useStyles' hook returns a function, which is then used to consume the styles. You may have already noticed some peculiar declarations, like a hook to which dependencies are passed, and some prefixes like &lt;code&gt;.&lt;/code&gt;,&lt;code&gt;&amp;amp;&lt;/code&gt;,&lt;code&gt;$&lt;/code&gt;and&lt;code&gt;:&lt;/code&gt;. Next, when we look at the definition of the styles, we'll see what they mean.&lt;/p&gt;

&lt;p&gt;useStyles provides you with the &lt;code&gt;GlobalStyles&lt;/code&gt; and &lt;code&gt;Styles&lt;/code&gt; functions to define global and local styles.&lt;/p&gt;

&lt;p&gt;Global styles:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Component's styles:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We are not going to analyze in detail each one of the functionalities, for that, you can consult the &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repository&lt;/a&gt;. But in summary, they can be explained as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Constants (&lt;code&gt;$&lt;/code&gt;): we can reuse them in other styles and components.&lt;/li&gt;
&lt;li&gt;Static styles (&lt;code&gt;.&lt;/code&gt;): regular styles that can be reused in other styles and components.&lt;/li&gt;
&lt;li&gt;Computed styles (&lt;code&gt;&amp;amp;&lt;/code&gt;): styles that depend on certain dependencies passed in the hook. If any dependency changes, these styles are re-computed.&lt;/li&gt;
&lt;li&gt;Paths (&lt;code&gt;:&lt;/code&gt;): shortcuts to write styles; e.g., to define the property &lt;code&gt;backgroundColor: 'red'&lt;/code&gt; you can use the path &lt;code&gt;bg:color:red&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;useStyles is a library created with the purpose of solving a recurring problem that developers usually have in React Native: disorganized and invasive styles in our components. With useStyles we use a hook to consume the styles, which gives us a simple, clean, and efficient interface.&lt;/p&gt;

&lt;p&gt;You're invited to check the &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;repository&lt;/a&gt; to see what else you can do with useStyles and check that this library will really ease your work as a developer. Of course, any contribution is welcome.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Read this article and more content in the Rootstrap blog: &lt;a href="https://www.rootstrap.com/blog"&gt;https://www.rootstrap.com/blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href="https://github.com/rootstrap/react-native-use-styles"&gt;https://github.com/rootstrap/react-native-use-styles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] &lt;a href="https://styled-components.com/"&gt;https://styled-components.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>javascript</category>
      <category>styles</category>
    </item>
  </channel>
</rss>
