<?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 Leonidez Acosta on Medium]]></title>
        <description><![CDATA[Stories by Leonidez Acosta on Medium]]></description>
        <link>https://medium.com/@leonidez?source=rss-a2d82d0ba347------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kg00S77glSrsnWXhc4OpOw.jpeg</url>
            <title>Stories by Leonidez Acosta on Medium</title>
            <link>https://medium.com/@leonidez?source=rss-a2d82d0ba347------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:21:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leonidez/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[Creating a Pattern for the new React Context API]]></title>
            <link>https://leonidez.medium.com/creating-a-pattern-for-the-new-react-context-api-ce87653e50b3?source=rss-a2d82d0ba347------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce87653e50b3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Leonidez Acosta]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 03:10:58 GMT</pubDate>
            <atom:updated>2018-04-04T03:10:58.297Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://reactjs.org/blog/2018/03/29/react-v-16-3.html">React 16.3</a> is now available, and one of the standout features is the new officially supported Context API. I’m currently exploring the refactor of a react/redux app, and I also just wanted to play around with a new toy, so I started testing out different usage patterns and the following is what I like best. Any tips or comments are always appreciated.</p><p>First, we begin by declaring a context:</p><pre>const { Provider, Consumer } = React.createContext()</pre><p>React.createContext returns us a Provider/Consumer pair that will allow context to be consumed no matter how deeply nested the Consumer is in the Provider. My idea is to use neither Provider nor Consumer directly, and in the case of the Provider, to wrap the Provider in a container component and manage its context as internal state.</p><pre>class CountProvider extends Component {<br>  state = {<br>    value: 0,<br>  }</pre><pre>  increment = () =&gt; {<br>    this.setState({ value: this.state.value + 1 })<br>  }</pre><pre>  decrement = () =&gt; {<br>   this.setState({ value: this.state.value - 1 })<br>  }</pre><pre>  createContext = () =&gt; {<br>    return {<br>      ...this.state,<br>      increment: this.increment,<br>      decrement: this.decrement<br>    }<br>  }</pre><pre>  render() {<br>    const context = this.createContext()<br>    return (<br>      &lt;Provider value={context}&gt;<br>        {this.props.children}<br>      &lt;/Provider&gt;<br>    )<br>  }<br>}</pre><p>Notice that, in addition to the state itself, we are also passing the methods by which to manipulate it. We can put our CountProvider at the root of our app (I would actually make a &lt;Providers&gt; component and just put all of them in there), and that would basically be it as far as setting up the Provider!</p><p>The following is what the use of context looks like. We are using the consumer provided by React in a higher order component called withContext, which will inject the react context into our presentation component using the name property in our settings object.</p><pre>import React, { Fragment } from &#39;react&#39;;<br>import { withContext } from &#39;./withContext&#39;;<br>import { CountConsumer } from &#39;./CountContext&#39;;</pre><pre>const Count = ({ count }) =&gt; (<br>  &lt;Fragment&gt;<br>    &lt;p&gt;<br>      Value: {count.value}<br>    &lt;/p&gt;<br>    &lt;button onClick={count.increment}&gt;<br>      Increment<br>    &lt;/button&gt;<br>    &lt;button onClick={count.decrement}&gt;<br>      Decrement<br>    &lt;/button&gt;<br>  &lt;/Fragment&gt;<br>)</pre><pre>export default withContext(CountConsumer, {<br>  name: &#39;count&#39;<br>})(Count)</pre><p>What does withContext look like?</p><pre>import React from &#39;react&#39;</pre><pre>const withContext = (Consumer, settings) =&gt; Component =&gt; props =&gt; (<br>  &lt;Consumer&gt;<br>    {context =&gt; (<br>      &lt;Component {...props} {...{ [settings.name]: context }} /&gt;<br>    )}<br>  &lt;/Consumer&gt;<br>)</pre><pre>export default withContext</pre><p>Here we’re turning the function-as-child pattern into a composition pattern, mostly because I prefer abstracting the use of the Consumer, which seems given to a uniform implementation of just always calling a component with its context. Also, by passing a settings object and using a different prop name for each context, it makes possible the ability to use multiple contexts in a single component without having the rightward drift of many &lt;Consumer&gt; components.</p><p>If we need multiple contexts, it’s as simple as wrapping calls to withContext in a compose function:</p><pre>export default compose(<br>  withContext(CountConsumer, { name: &#39;count&#39; }),<br>  withContext(UsersConsumer, { name: &#39;users&#39; })<br>)(CountAndUsers)</pre><p>In this case count and users will both be available as props on our component. An important side benefit is that, since we’re using the composition pattern, we can migrate redux state into React’s new context incrementally, as calls to redux’s connect can live side by side with calls to withContext in a compose call, as long as there are no prop name collisions.</p><p>That’s it, let me know what ya think!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce87653e50b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I Think About While Programming]]></title>
            <link>https://leonidez.medium.com/what-i-think-about-while-programming-9b358671d962?source=rss-a2d82d0ba347------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b358671d962</guid>
            <category><![CDATA[mentorship]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Leonidez Acosta]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 02:13:26 GMT</pubDate>
            <atom:updated>2017-10-16T03:18:12.319Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been a developer for three and a half years, and am now to the point that I mentor the more junior developers at my company. I took some time recently to help one of my colleagues plan out a project, and our conversation turned to a particular habit of thought that I felt the need to address in this post.</p><p>As anyone who has written a program will know, the process involves a virtual forest of decision trees. Beginners make a lot of these decisions unconsciously or not at all, to the detriment of their programs. I believe this comes from neglecting the one most important decision that is faced when programming: deciding what to think about.</p><p>My colleague related a story to me of how he was brought into a project to add a feature, proceeded to work on the feature, and as he was pursuing his solution discovered a dependency issue that brought his work to a standstill. The concept of his solution led him to rely on the dependency, and now that the dependency was known not to be reliable he began to troubleshoot his new, dependency-specific problem. He had been taken out of the way of his work to perform work that, in the middle of his propulsion, he was not aware that he should eject himself from. He had in short made the classic error of not being able to see the forest for the trees, or even the trees for the branches, and wanted advice on how to avoid this situation in the future.</p><p>I told him that the solution here is to adopt a habit of vigilance, to remember always that the code we see on the screen represents a past thought, a record of previous motives and priorities. It is the mark of our growth as developers that we do not let this code decide what it is we think about, rather that we take it as the starting point for our own applications.</p><p>I try to keep this in mind any time I program, and though not always successful, I feel the attempt makes for better work. Hopefully the thought may do the same for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b358671d962" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>