<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ismael Teixeira on Medium]]></title>
        <description><![CDATA[Stories by Ismael Teixeira on Medium]]></description>
        <link>https://medium.com/@ismaeljtl?source=rss-f2a550d28102------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bos0m9dwBLzqc_23rH_1KA.jpeg</url>
            <title>Stories by Ismael Teixeira on Medium</title>
            <link>https://medium.com/@ismaeljtl?source=rss-f2a550d28102------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 17:59:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ismaeljtl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React.js: Optimizing performance in our app with memo]]></title>
            <link>https://medium.com/@ismaeljtl/react-js-optimizing-performance-in-our-app-with-memo-a9db7a66c2de?source=rss-f2a550d28102------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9db7a66c2de</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Ismael Teixeira]]></dc:creator>
            <pubDate>Tue, 01 Aug 2023 10:54:04 GMT</pubDate>
            <atom:updated>2023-08-01T10:54:04.762Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In the React.js world, memo is a valuable tool for improving the performance of our functional components, allowing them to avoid unnecessary renderings when their props have not changed. However, it is essential to understand that in certain scenarios, memo will not solve all performance issues, especially when our components contain a local state that mutates. In this article, we will delve into the use of memo, explore situations where it may not improve performance, and present an effective solution to address this problem.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UoflaI-aQjAGFGU2" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In React.js, memo is a higher Order Component (HOC) that when we apply to a component, React will take care of memorizing the result of the last render and will only render it again when the past props change. This means that if the props remain the same between renderings, the component will avoid re-rendering itself again, which improves the efficiency of our components <strong>(we say that a component has been memoized when it behaves this way).</strong></p><p>Although memo can improve the performance of many components, it is not a magic solution in all cases. If a component contains a local state that mutates, memo will not be able to detect these changes, as it only relies on comparisons of props references (current vs past props). It is in these cases that we must separate our components into Parent and Child components, the Parent component will be in charge of owning the logic and the state, while the Child component will only be in charge of receiving the props and displaying them (remember the famous pattern of smart and dumb components).</p><p>A clear example for this use case can be the forms.</p><p>If in our component we have a form with internal state and we have several elements in it, we can clearly identify that the fact that the state of one of the elements changes will make the other elements also be re-rendered again without the need of it. It is here where we can separate our form in custom atomized components (like inputs, checkboxes, etc) where they are only in charge of showing the received props and make sure that with memo no unwanted re-renderings are made.</p><p>Another issue that we must take into account is the minimization of the props that receive our memoized components and the type of these. Recall that in JavaScript native values are evaluated by value, but objects are evaluated by reference, so we know that 3 equals 3, but {} is not the same as {}. Because of this we must:</p><ul><li>Always try to separate the props that our child component receives:</li></ul><pre>function Page() {<br>  const [name, setName] = useState(&#39;Taylor&#39;);<br>  const [age, setAge] = useState(42);<br>  return &lt;Profile name={name} age={age} /&gt;;<br>}<br><br>const Profile = memo(function Profile({ name, age }) {<br>  // ...<br>});</pre><p>And if this is not possible then use usememo to ensure that our parent component does not perform unnecessary calculations:</p><pre>function Page() {<br>  const [name, setName] = useState(&#39;Taylor&#39;);<br>  const [age, setAge] = useState(42);<br><br>  const person = useMemo(<br>    () =&gt; ({ name, age }),<br>    [name, age]<br>  );<br><br>  return &lt;Profile person={person} /&gt;;<br>}<br><br>const Profile = memo(function Profile({ person }) {<br>  // ...<br>});</pre><p>Hope this brief explanation has helped you understand what memo is, so let me know what you thought of this brief explanation and if you have other comments to offer, I would love to hear them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9db7a66c2de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React.js: Optimizando el rendimiento de nuestra app con memo]]></title>
            <link>https://medium.com/@ismaeljtl/react-js-optimizando-el-rendimiento-de-nuestra-app-con-memo-6fe86020bf57?source=rss-f2a550d28102------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fe86020bf57</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ismael Teixeira]]></dc:creator>
            <pubDate>Tue, 01 Aug 2023 10:46:30 GMT</pubDate>
            <atom:updated>2023-08-01T10:46:30.895Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>En el mundo de React.js, <a href="https://react.dev/reference/react/memo"><strong><em>memo</em></strong></a> es una herramienta valiosa para mejorar el rendimiento de nuestros componentes funcionales, permitiéndoles evitar renderizaciones innecesarias cuando sus props no han cambiado. Sin embargo, es esencial comprender que en ciertos escenarios, <em>memo</em> no resolverá todos los problemas de rendimiento, especialmente cuando nuestros componentes contienen un estado local que muta. En este artículo, profundizaremos en el uso de <em>memo</em>, exploraremos situaciones en las que puede no mejorar el rendimiento y presentaremos una solución efectiva para abordar este problema.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SHpG0eKhuSI8IX9e" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>En React.js, <em>memo</em> es una función de orden superior (HOC) que cuando aplicamos a un componente, React se encargará de memorizar el resultado del último render y solo lo volverá a renderizar cuando las props pasadas cambien. Esto significa que si las props se mantienen iguales entre renderizaciones, el componente evitará renderizarse nuevamente, lo que mejora la eficiencia de nuestros componentes <strong>(decimos que un componente se ha memoizado cuando se comporta de esta manera).</strong></p><p>Aunque <em>memo</em> puede mejorar el rendimiento de muchos componentes, no es una solución mágica en todos los casos. Si un componente contiene un estado local que muta, <em>memo</em> no podrá detectar estos cambios, ya que solo se basa en las comparaciones de las referencias de las props (props actuales vs props pasadas). Es en estos casos en que debemos de separar nuestros componentes en Padres e Hijos, el componente Padre se encargará de poseer la lógica y el estado, mientras que el componente Hijo solo se encargará de recibir las props y mostrarlas (recordemos el famoso patrón de componentes inteligentes y tontos o smart and dumb components).</p><p>Un ejemplo claro para este caso de uso pueden ser los formularios. Si en nuestro componente tenemos un formulario con estado interno y poseemos varios elementos en el podemos claramente identificar que el hecho de que el estado de uno de los elementos cambie hará que los otros elementos tambien se rendericen nuevamente sin necesidad de ello. Es aquí donde podemos separar nuestro formulario en componentes atomizados (como inputs, checkboxes, etc) donde solo se encarguen de mostrar las props recibidas y asegurarnos de que con <em>memo</em> no se realicen renderizados no deseados.</p><p>Otra cuestión que debemos de tener en cuenta es la minimización de las props que reciben nuestros componentes <em>memoizados </em>y el tipo de estos. Recordemos que en Javascript los valores nativos son evaluados por valor, pero los objetos son evaluados por referencia, por lo que sabemos que 3 es igual a 3, pero {} no es lo mismo que {}. Debido a esto debemos:</p><ul><li>Siempre tratar de separar las props que recibe nuestro componente hijo:</li></ul><pre>function Page() {<br>  const [name, setName] = useState(&#39;Taylor&#39;);<br>  const [age, setAge] = useState(42);<br>  return &lt;Profile name={name} age={age} /&gt;;<br>}<br><br>const Profile = memo(function Profile({ name, age }) {<br>  // ...<br>});</pre><ul><li>Y si esto no es posible entonces usar <em>usememo</em> para asegurarnos que nuestro componente padre no realice cálculos innecesarios:</li></ul><pre>function Page() {<br>  const [name, setName] = useState(&#39;Taylor&#39;);<br>  const [age, setAge] = useState(42);<br><br>  const person = useMemo(<br>    () =&gt; ({ name, age }),<br>    [name, age]<br>  );<br><br>  return &lt;Profile person={person} /&gt;;<br>}<br><br>const Profile = memo(function Profile({ person }) {<br>  // ...<br>});</pre><p>Espero esta breve explicaciön te haya podido ayudar a entender que es memo, asi que cuéntame qué te ha parecido esta breve explicación y si tienes otros comentarios que ofrecerme, me encantaria escucharlos.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fe86020bf57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useRef: Overcoming Lifecycle Challenges with Persistent Values in React]]></title>
            <link>https://medium.com/@ismaeljtl/useref-overcoming-lifecycle-challenges-with-persistent-values-in-react-1e3cb4c5ec52?source=rss-f2a550d28102------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e3cb4c5ec52</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Ismael Teixeira]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 16:22:39 GMT</pubDate>
            <atom:updated>2023-01-18T16:22:39.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rXTM01J1Nar7Qq1bwqwkA.png" /></figure><blockquote>When developing applications with React, it is common to have the need to reference values of any type at different times. Whether it is to handle DOM elements, maintain persistence of values over several re-renders or even escape the lifecycle defined by React. For this there is a very useful tool: the useRef hook. In this article, we will explore in depth what is useRef, how it works and how to take full advantage of its benefits in our React applications.</blockquote><p>These days I went through the <a href="http://beta.reactjs.org/">React.js beta documentation</a> to learn a little bit more about a really important hook in React.js: useRef. In this article I will try to give you a summary of what I could read and learn in order to help you to better understand the concept and the usefulness of this hook.</p><p>To begin with, you must have in mind that the hook useRef serves to reference a value of any type (numbers, strings, objects or even DOM elements) inside your React application. The definition of a variable with this hook looks like this:</p><pre>const ref = useRef(0)</pre><p>and now our ref variable will have the following structure:</p><pre>ref = {<br>  current: 0<br>}</pre><p>So when thinking about Refs it is very important to remember that the stored values are inside the current property.</p><p>But if you’re like me, you probably have in mind that useRef is largely used for handling DOM elements, this is true, but it really goes beyond that. Basically, useRef is used to store the information of a component without generating a new render, something like a useState that does not generate a new render, and the thing with it is that if you read the documentation you will see that when they explain the concept of useRef they comment that this hook was introduced with the objective of being an “escape hatche” to the life cycle defined by React.</p><p>But why would you want to avoid the React lifecycle and not generate a new render in my application? Refs are really useful to maintain the persistence of any kind of value throughout one or several re-renders, in this way, we can solve the volatility of local variables in our components. If you haven’t understood any of this I am sure that a simple example will help you to see it in a better way.</p><p>In the code that I show you below we have a component that renders a text input with a button to send a message. Once the Send button has been clicked another button appears to Undo the message. The message will be sended 3 seconds after clicking the Send button, but if you test this code and at the moment of sending the message you click the Undo button you will realize that in spite of that the message is sent in the same way. This component is not working the way we expect. Here you have the code.</p><pre>import { useState } from &#39;react&#39;;<br><br>export default function Chat() {<br>  const [text, setText] = useState(&#39;&#39;);<br>  const [isSending, setIsSending] = useState(false);<br>  let timeoutID = null;<br><br>  function handleSend() {<br>    setIsSending(true);<br>    timeoutID = setTimeout(() =&gt; {<br>      alert(&#39;Sent!&#39;);<br>      setIsSending(false);<br>    }, 3000);<br>  }<br><br>  function handleUndo() {<br>    setIsSending(false);<br>    clearTimeout(timeoutID);<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;input<br>        disabled={isSending}<br>        value={text}<br>        onChange={e =&gt; setText(e.target.value)}<br>      /&gt;<br>      &lt;button<br>        disabled={isSending}<br>        onClick={handleSend}&gt;<br>        {isSending ? &#39;Sending…&#39; : &#39;Send&#39;}<br>      &lt;/button&gt;<br>      {isSending &amp;&amp;<br>        &lt;button onClick={handleUndo}&gt;<br>          Undo<br>        &lt;/button&gt;<br>      }<br>    &lt;/&gt;<br>  );<br>}</pre><p>What is happening here is that the local variable with the name timeoutID, in charge of saving the ID of our setTimeout is being initialized when a re-render occurs, causing us to lose the ID that we needed to cancel the timeout. The way we can keep that ID despite the re-render is through a Ref! Below I show you the solution with the useRef hook.</p><pre>import { useState, useRef } from &#39;react&#39;;<br><br>export default function Chat() {<br>  const [text, setText] = useState(&#39;&#39;);<br>  const [isSending, setIsSending] = useState(false);<br>  const timeoutRef = useRef(null);<br><br>  function handleSend() {<br>    setIsSending(true);<br>    timeoutRef.current = setTimeout(() =&gt; {<br>      alert(&#39;Sent!&#39;);<br>      setIsSending(false);<br>    }, 3000);<br>  }<br><br>  function handleUndo() {<br>    setIsSending(false);<br>    clearTimeout(timeoutRef.current);<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;input<br>        disabled={isSending}<br>        value={text}<br>        onChange={e =&gt; setText(e.target.value)}<br>      /&gt;<br>      &lt;button<br>        disabled={isSending}<br>        onClick={handleSend}&gt;<br>        {isSending ? &#39;Sending…&#39; : &#39;Send&#39;}<br>      &lt;/button&gt;<br>      {isSending &amp;&amp;<br>        &lt;button onClick={handleUndo}&gt;<br>          Undo<br>        &lt;/button&gt;<br>      }<br>      &lt;/&gt;<br>  );<br>}</pre><p>You can find this example and others in the new official React documentation, here is the <a href="https://beta.reactjs.org/learn/referencing-values-with-refs">link</a>.</p><p>I found this example the most appropriate and interesting to explore the concept of Refs in React. It is important to keep in mind that Refs are a great solution offered by the React team, but they do not replace the use of states in our application. Remember that if you have a lot of logic and the data flow of your application depends on Refs, you can start to analyze that you should rethink the way you are writing your component.</p><p>Let me know what you think about this brief explanation about this hook, I would love to hear your comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e3cb4c5ec52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useRef: Superando los desafíos del ciclo de vida con valores persistentes en React]]></title>
            <link>https://medium.com/@ismaeljtl/useref-superando-los-desaf%C3%ADos-del-ciclo-de-vida-con-valores-persistentes-en-react-92a3964205bc?source=rss-f2a550d28102------2</link>
            <guid isPermaLink="false">https://medium.com/p/92a3964205bc</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Ismael Teixeira]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 16:08:49 GMT</pubDate>
            <atom:updated>2023-01-18T16:08:49.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rXTM01J1Nar7Qq1bwqwkA.png" /></figure><blockquote><em>En el desarrollo de aplicaciones con React, es común tener la necesidad de referenciar valores de cualquier tipo en diferentes momentos. Ya sea para manejar elementos del DOM, mantener la persistencia de valores a lo largo de varios re-renders o incluso escapar del ciclo de vida definido por React. Para esto existe una herramienta muy útil: el hook useRef. En este artículo, vamos a explorar en profundidad qué es useRef, cómo funciona y cómo podemos aprovechar al máximo sus beneficios en nuestras aplicaciones React.</em></blockquote><p>En estos días me pasé por la <a href="https://beta.reactjs.org/">documentación beta de React.js</a> para aprender un poco más acerca de un hook realmente importante en esta librería: useRef. En este artículo intentaré darte un resumen de lo que pude leer y aprender con el fin de poder ayudarte a entender mejor el concepto y la utilidad de este hook.</p><p>Para comenzar, debes tener en mente que el hook useRef sirve para referenciar un valor de cualquier tipo (numeros, strings, objetos y hasta elementos del DOM) dentro de tu aplicación React. La definición de una variable con este hook se ve así:</p><pre>const ref = useRef(0)</pre><p>y nuestra variable ref tendría la siguiente estructura:</p><pre>ref = {<br>  current: 0<br>}</pre><p>Por lo que a la hora de pensar en Refs es muy importante recordar que los valores almacenados se encuentran dentro de la propiedad current.</p><p>Pero si eres como yo, probablemente tendrás en mente que useRef es en gran parte utilizado para el manejo de elementos del DOM, esto es cierto, pero realmente va más allá. Básicamente, useRef es utilizado para guardar información de un componente sin generar un nuevo render, algo así como un useState que no genera un nuevo render, y es que, si lees la documentación veras que cuando explican el concepto de este hook comentan que fue introducido con el objetivo de ser una “vía de escape” al ciclo de vida definido por React.</p><p>Pero, ¿por qué desearía evitar el ciclo de vida definido por React y no generar un nuevo render en mi aplicación? Las Refs son realmente útiles para mantener la persistencia de cualquier tipo de valor a lo largo de uno o varios re-renders, de este modo, podemos solventar la volatilidad de variables locales en nuestros componentes. Si no has entendido nada de esto estoy seguro que un simple ejemplo te ayudará a verlo de una mejor manera.</p><p>En el código que te muestro a continuación tenemos un componente que renderiza un input de texto con un botón para enviar dicho mensaje. Una vez que se ha pulsado en el botón Enviar aparece otro botón para Cancelar dicho envío. El envío del mensaje ocurre 3 segundos después de clicar el botón Enviar, pero si pruebas este código y al momento de enviar un mensaje cliqueas el botón de Cancelar te darás cuenta que a pesar de eso el mensaje se envía de igual manera. Este componente no está funcionando de la manera en la que esperamos.</p><pre>import { useState } from &#39;react&#39;;<br><br>export default function Chat() {<br>  const [text, setText] = useState(&#39;&#39;);<br>  const [isSending, setIsSending] = useState(false);<br>  let timeoutID = null;<br><br>  function handleSend() {<br>    setIsSending(true);<br>    timeoutID = setTimeout(() =&gt; {<br>      alert(&#39;Sent!&#39;);<br>      setIsSending(false);<br>    }, 3000);<br>  }<br><br>  function handleUndo() {<br>    setIsSending(false);<br>    clearTimeout(timeoutID);<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;input<br>        disabled={isSending}<br>        value={text}<br>        onChange={e =&gt; setText(e.target.value)}<br>      /&gt;<br>      &lt;button<br>        disabled={isSending}<br>        onClick={handleSend}&gt;<br>        {isSending ? &#39;Sending…&#39; : &#39;Send&#39;}<br>      &lt;/button&gt;<br>      {isSending &amp;&amp;<br>        &lt;button onClick={handleUndo}&gt;<br>          Undo<br>        &lt;/button&gt;<br>      }<br>    &lt;/&gt;<br>  );<br>}</pre><p>Lo que está sucediendo aquí es que la variable local con el nombre timeoutID, encargada de guardar el ID de nuestro setTimeout está siendo inicializada cada vez que ocurre un re-render, ocasionando que perdamos el ID que necesitábamos para cancelar el timeout. La manera en que podemos conservar dicho ID a pesar del re-render es a través de una Ref! A continuación te muestro la solución al problema anterior con el uso del hook useRef.</p><pre>import { useState, useRef } from &#39;react&#39;;<br><br>export default function Chat() {<br>  const [text, setText] = useState(&#39;&#39;);<br>  const [isSending, setIsSending] = useState(false);<br>  const timeoutRef = useRef(null);<br><br>  function handleSend() {<br>    setIsSending(true);<br>    timeoutRef.current = setTimeout(() =&gt; {<br>      alert(&#39;Sent!&#39;);<br>      setIsSending(false);<br>    }, 3000);<br>  }<br><br>  function handleUndo() {<br>    setIsSending(false);<br>    clearTimeout(timeoutRef.current);<br>  }<br><br>  return (<br>    &lt;&gt;<br>      &lt;input<br>        disabled={isSending}<br>        value={text}<br>        onChange={e =&gt; setText(e.target.value)}<br>      /&gt;<br>      &lt;button<br>        disabled={isSending}<br>        onClick={handleSend}&gt;<br>        {isSending ? &#39;Sending…&#39; : &#39;Send&#39;}<br>      &lt;/button&gt;<br>      {isSending &amp;&amp;<br>        &lt;button onClick={handleUndo}&gt;<br>          Undo<br>        &lt;/button&gt;<br>      }<br>      &lt;/&gt;<br>  );<br>}</pre><p>Recuerda que puedes encontrar este ejemplo y otros mas en la nueva documentacion oficial de React, aqui te dejo el <a href="https://beta.reactjs.org/learn/referencing-values-with-refs">enlace</a>.</p><p>Este ejemplo me ha parecido el más adecuado e interesante de explorar en el concepto de las Refs en React. Es importante que tengamos en cuenta que las Refs son una gran solución ofrecida por el equipo de React, pero no sustituyen al uso de estados en nuestra aplicación. Recuerda que si mucha lógica y flujo de datos de tu código está dependiendo del uso de Refs, puedes empezar a repensar la forma en la que estás escribiendo tu componente.</p><p>Cuéntame qué te ha parecido esta breve explicación sobre este hook, me encantará escuchar tus comentarios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92a3964205bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>