<?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>Forem: Vanderlei Alves da Silva</title>
    <description>The latest articles on Forem by Vanderlei Alves da Silva (@vanderleisilva).</description>
    <link>https://forem.com/vanderleisilva</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%2F228989%2F1786581b-18b2-43c9-98a7-534450375920.jpg</url>
      <title>Forem: Vanderlei Alves da Silva</title>
      <link>https://forem.com/vanderleisilva</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vanderleisilva"/>
    <language>en</language>
    <item>
      <title>Bringing Web3 Principles to Enterprise Systems</title>
      <dc:creator>Vanderlei Alves da Silva</dc:creator>
      <pubDate>Mon, 27 Oct 2025 07:26:02 +0000</pubDate>
      <link>https://forem.com/vanderleisilva/bringing-web3-principles-to-enterprise-systems-317o</link>
      <guid>https://forem.com/vanderleisilva/bringing-web3-principles-to-enterprise-systems-317o</guid>
      <description>&lt;p&gt;While getting back to the basics of the blockchain architecture some rather philosophical thoughts just popped up into my mind, the enterprise software landscape is build around centralized platforms, potentially build in a distributed manner but vendor locked-in, and opaque systems that businesses have accepted as "just how things work." But ...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What if these systems were built on fundamentally different way? On Web3 principles? How would they look like??&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article series explores this question through a proof-of-concept: a blockchain-based booking system that aims to validate whether Web3 principles can address real enterprise challenges while meeting strict regulatory requirements like GDPR.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web3.0: Is that still a thing?
&lt;/h2&gt;

&lt;p&gt;Though the cryptocurrencies continue steady striving the term Web3.0 doesn't feel to follow the same path. Looking by the main articles on the topic most of them used to date back 2 to 3 years, we could naturally argue that the boom of AI and the shallow specialists writing about it everywhere, have left the internet a bit more "poor" in terms of variety of content, still the way I see it, the web3.0 term sounded more as a philosophical aspirational goal, which is likely not to achieve its full idealized potential.&lt;/p&gt;

&lt;p&gt;Letting the philosophical discussion aside and going into the interesting engineering part, at its essence, Web3.0 proposes five architectural principles: &lt;strong&gt;decentralization&lt;/strong&gt; (distributed control instead of central authority), &lt;strong&gt;user ownership&lt;/strong&gt; (individuals own their data and digital assets), &lt;strong&gt;transparency&lt;/strong&gt; (verifiable systems and open rules), &lt;strong&gt;trustless architecture&lt;/strong&gt; (smart contracts execute automatically without intermediaries), and &lt;strong&gt;composability&lt;/strong&gt; (interoperable systems that work together through open standards).&lt;/p&gt;

&lt;p&gt;These aren't just blockchain buzzwords. They represent a fundamentally different way to architect systems—one that addresses real enterprise pain points like vendor lock-in, opaque pricing, high intermediary costs, and data privacy concerns.&lt;/p&gt;

&lt;p&gt;With that in mind I want to propose the following exercise:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Can we extract its valuable principles and apply them pragmatically to solve real business problems?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Booking Platform POC: Validating Web3 Principles
&lt;/h2&gt;

&lt;p&gt;To explore whether these principles work in practice, we need a concrete example. I will call it: &lt;strong&gt;blockchain-based booking system&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why a Booking Platform?
&lt;/h3&gt;

&lt;p&gt;Booking systems are ideal for this exploration because they:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Have clear business logic&lt;/strong&gt; - Rules for availability, pricing, and reservations are well-defined&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Involve multiple parties&lt;/strong&gt; - Customers, resource owners, and potentially intermediaries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Require trust&lt;/strong&gt; - Bookings must be honored; payments must be released&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle sensitive data&lt;/strong&gt; - Personal information, payment details, booking history&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Face real regulations&lt;/strong&gt; - GDPR compliance is mandatory in many markets&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we can build a booking system that embraces Web3 principles &lt;strong&gt;while&lt;/strong&gt; meeting regulatory requirements, we can much more confidently assert that the concept works for enterprise applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Specific Web3 Principles We're Testing
&lt;/h3&gt;

&lt;p&gt;This POC validates five key principles:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Decentralization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No central platform controls bookings&lt;/li&gt;
&lt;li&gt;Smart contracts manage state, not a company&lt;/li&gt;
&lt;li&gt;Anyone can verify the system's integrity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. User Ownership&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers control their booking data&lt;/li&gt;
&lt;li&gt;Data can be deleted on demand (GDPR "right to be forgotten")&lt;/li&gt;
&lt;li&gt;Booking records are portable across platforms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Transparency&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Booking logic visible in open-source smart contracts&lt;/li&gt;
&lt;li&gt;All transactions auditable on the blockchain&lt;/li&gt;
&lt;li&gt;Pricing rules are transparent and verifiable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Trustless Execution&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smart contracts automatically enforce booking rules&lt;/li&gt;
&lt;li&gt;Payments released when conditions are met&lt;/li&gt;
&lt;li&gt;No intermediary needed to arbitrate&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Privacy-Preserving Design&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Personal data never touches the blockchain&lt;/li&gt;
&lt;li&gt;Cryptographic hashing enables verification without exposure&lt;/li&gt;
&lt;li&gt;GDPR compliance through architectural design&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Are We Building?
&lt;/h3&gt;

&lt;p&gt;Below is the system architecture diagram showing how we're implementing these Web3 principles in practice:&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%2Fraw.githubusercontent.com%2Fvanderleisilva%2Fblockchain-booking-system%2Frefs%2Fheads%2Fmain%2Fassets%2Fsystem-architecture.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%2Fraw.githubusercontent.com%2Fvanderleisilva%2Fblockchain-booking-system%2Frefs%2Fheads%2Fmain%2Fassets%2Fsystem-architecture.png" width="800" height="725"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;User Interface Layer&lt;/strong&gt; serves as the entry point to the system, providing a command-line interface (CLI) built with Node.js and TypeScript. This layer represents the client, it could be any other kind of client, web page in the browser, mobile application, internet of things (IoT), you name it. But for this use-case to make things simpler, we go with a simple CLI application.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Application Layer&lt;/strong&gt; acts as the intelligent middleware that orchestrates all system operations. Let's think of it as a backend services which houses five critical services: the Blockchain Service interfaces with Ethereum using Ethers.js to handle all blockchain transactions; the Encryption Service to generate unique key pairs for each booking and performs AES-256-GCM encryption on personal data; the Storage Service which manages the lifecycle of encrypted data stored off-chain; the Wallet Manager securely handles user cryptographic identities and signing operations; and the Config Manager maintains network settings and system configuration. This layer is responsible for the critical separation between what goes on-chain (only hashes) and what stays off-chain (encrypted personal data). More on that later :)&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Blockchain Layer&lt;/strong&gt; represents the immutable, transparent core of the system running on Ethereum. At its heart are smart contracts written in Solidity that contain all booking business logic—resource management, availability checking, and booking state transitions. These contracts interact with the broader Ethereum network through a JSON-RPC Provider that connects to Ethereum nodes. Crucially, this layer stores only cryptographic hashes and public booking metadata (dates, prices, status) while keeping zero personal information. The blockchain serves as the source of truth for booking existence and availability, providing transparency and preventing double-booking through distributed consensus.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Off-Chain Storage Layer&lt;/strong&gt; is the privacy-preserving counterpart to the blockchain, designed specifically to handle sensitive personal data in a GDPR-compliant manner. It consists of an Encrypted Data Store (PostgreSQL, MongoDB, or any other storing mechanism) that holds encrypted personal information, a separate Key Vault that stores encryption keys in isolation from the data they protect, and a Privacy API that manages GDPR operations like data export and the "right to be forgotten." The architectural decision to separate encrypted data from encryption keys is critical—when a user requests deletion, removing the keys makes the encrypted data mathematically irretrievable, achieving GDPR compliance while leaving blockchain hashes untouched.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Storage component&lt;/strong&gt; represents two distinct persistence mechanisms: Local Storage for user-side data like wallet keystores and configuration files, and On-Chain Storage within the blockchain itself that holds only hashes and non-sensitive booking metadata. This dual storage approach reinforces the system's privacy-first design—sensitive data never crosses into blockchain storage, while blockchain benefits (immutability, transparency, auditability) are preserved through cryptographic hashes that prove data existence without revealing its contents. The integration between these storage types is mediated entirely through the Application Layer, which ensures proper encryption, hashing, and separation of concerns throughout the data lifecycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ethereum as the Blockchain Platform
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ethereum&lt;/strong&gt; for those who still may be in doubt of what exactly it is, is a decentralized computing platform that runs on a global network of computers instead of a central server. This means that no single company controls the system, a capability we are really looking for this exercise, and applications built on Ethereum — called decentralized apps (&lt;strong&gt;dApps&lt;/strong&gt;) — continue to run as long as the network exists.&lt;/p&gt;

&lt;p&gt;For a booking platform, Ethereum and dApps bring interesting possibilities. Instead of depending on one central business to record reservations, availability and payments, the blockchain can ensure the records are shared, trusted, and consistent across all participants — hotels, partners, and users. Smart contracts could automatically handle payments, deposits, cancellations, loyalty points, insurance, or secondary resale of bookings without intermediaries. And since the system is open and auditable, fraud and double-booking become much harder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coming Up Next
&lt;/h2&gt;

&lt;p&gt;This article aimed to establish the &lt;strong&gt;why&lt;/strong&gt; Web3 principles matter and &lt;strong&gt;what&lt;/strong&gt; we're building. The next articles will dive into &lt;strong&gt;how&lt;/strong&gt;, exploring the implementation in details, having a bit of fun in the way while playing with: Ethereum blockchain platform, Solidity code, business logic on-chain, and how to build contracts that enforce rules transparently while respecting privacy.&lt;/p&gt;

&lt;h2&gt;
  
  
  View the Architecture
&lt;/h2&gt;

&lt;p&gt;If you got interested and want to dive into all details just goal ahead in the following link to the public repo, which though still a WIP, already have an extensive system architecture in place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/vanderleisilva/blockchain-booking-system/blob/main/diagrams/01-system-architecture.md" rel="noopener noreferrer"&gt;System Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/vanderleisilva/blockchain-booking-system/tree/main/diagrams" rel="noopener noreferrer"&gt;All Diagrams&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or view the complete codebase on &lt;a href="https://github.com/vanderleisilva/blockchain-booking-system" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A piece o merchandising
&lt;/h2&gt;

&lt;p&gt;Lastly a small pause for sharing you some very exciting new, at least for myself :), recently I've just released my first book:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.vanderleialves.com/micro-frontend-book?utm_source=dev.to"&gt;Micro Frontends Architecture for Scalable Applications&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which bring lots of architectural insights about the frontend development, and more specifically about the micro-frontends, go a head have a look and let me know your thoughts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Did you find not connected to &lt;em&gt;web3.0&lt;/em&gt;, &lt;em&gt;blockchains&lt;/em&gt; and this article at all? Yeah, indeed is not, but why would we put boxes around what we can work/learn if we can explore them all ...&lt;/p&gt;

&lt;p&gt;Thanks for reading and let me know your thoughts/feedbacks/comments and or any other thing you may find relevant to share!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>ethereum</category>
      <category>architecture</category>
    </item>
    <item>
      <title>NextJS Progressive Web App</title>
      <dc:creator>Vanderlei Alves da Silva</dc:creator>
      <pubDate>Tue, 17 Mar 2020 07:36:54 +0000</pubDate>
      <link>https://forem.com/vanderleisilva/nextjs-progressive-web-app-4mkk</link>
      <guid>https://forem.com/vanderleisilva/nextjs-progressive-web-app-4mkk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;What if we could quickly setup a progressive web app, with server side rendering and routing mechanism out of the box? Would that sound interesting? That’s why you here, stick with me and enjoy the road.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It all starts with &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;NextJS&lt;/a&gt;, we install it and run it as the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first question that come up is why would we go to a different approach to start a react project other then &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt;? The question is pretty straightforward, if you wanna have &lt;a href="https://alligator.io/react/server-side-rendering/" rel="noopener noreferrer"&gt;server side rendering&lt;/a&gt; and a better and easy way to work offline. You not sure? Here it goes …&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;create-react-app&lt;/strong&gt; comes out of the box with an offline support, however it’s restricted in how stores locally its assets. It restricts us to the generated assets (js, css, images, fonts ...), however what if you also wanna store CDN files, backend apis, system specific routing? How would go there, probably &lt;a href="https://create-react-app.dev/docs/available-scripts/#npm-run-eject" rel="noopener noreferrer"&gt;ejecting&lt;/a&gt; your project and(or) using other libraries, such as &lt;a href="https://www.npmjs.com/package/react-app-rewired" rel="noopener noreferrer"&gt;react-app-rewired&lt;/a&gt;, but at the end these approaches soon or late end up adding more complexity to your code and more code to maintain .. Anyway why would you enjoy maintaining custom script building systems? &lt;/p&gt;

&lt;p&gt;Now take a look at this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isProd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withPWA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next-pwa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;withPWA&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
 &lt;span class="na"&gt;pwa&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;disable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isProd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;dest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a simple &lt;a href="https://eloquentjavascript.net/05_higher_order.html" rel="noopener noreferrer"&gt;higher order function&lt;/a&gt; we add the desired functionality! Too fast? Let’s digest this properly.&lt;/p&gt;

&lt;p&gt;First thing first, have a look on this &lt;a href="https://cocky-raman-3845d9.netlify.com/" rel="noopener noreferrer"&gt;dummy example&lt;/a&gt; (if you wanna fully experience all features, use chrome, nothing against the others, but while I’m writing this article, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps" rel="noopener noreferrer"&gt;progressive web app&lt;/a&gt; functionalities are still a work in progress and the installable option of our app will not work on them)&lt;/p&gt;

&lt;p&gt;Once you there, open the developer tools and check while you navigate and/or refresh the pages, the resource (js, css, fonts, api calls ..) are being locally saved:&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%2Fi%2Fkofd945yxe9xbzb3bjyb.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%2Fi%2Fkofd945yxe9xbzb3bjyb.png" alt="Saved assets" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check also on the plus icon right after the website url bar:&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%2Fi%2Fd5pthd7812c5bi48zzry.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%2Fi%2Fd5pthd7812c5bi48zzry.png" alt="Installable option" width="374" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you inspect the network tab, you’ll see that the initial load comes with all your app already rendered from your server .. :)&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%2Fi%2Fm59pwvau04rmarhie3ot.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%2Fi%2Fm59pwvau04rmarhie3ot.png" alt="Server side rendering" width="800" height="858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it, these are the user functionalities of our dummy app, disable the internet connection and then you can see a friendly message saying that there is no connection and the app still working.&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%2Fi%2Fjwrdaqfxphbdamskganx.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%2Fi%2Fjwrdaqfxphbdamskganx.png" alt="Server side rendering" width="800" height="853"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;But then now it comes the question, how is that done? Tired of reading? Go directly to what matters: &lt;a href="https://github.com/vanderleisilva/next-pwa" rel="noopener noreferrer"&gt;the code&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;The implementation is as &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;NextJS&lt;/a&gt; project, using &lt;a href="https://material-ui.com/" rel="noopener noreferrer"&gt;MaterialUI&lt;/a&gt; for the interface elements, &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;Typescript&lt;/a&gt; for type checking, &lt;a href="https://www.npmjs.com/package/next-pwa" rel="noopener noreferrer"&gt;next-pwa&lt;/a&gt; a next plugin for the progressive web app functionalities and a quick bonus, check &lt;a href="https://github.com/vanderleisilva/next-pwa/blob/master/pages/my-mdx.mdx" rel="noopener noreferrer"&gt;this code&lt;/a&gt;. An MDX support for next provided by &lt;a href="https://github.com/zeit/next.js/tree/canary/packages/next-mdx" rel="noopener noreferrer"&gt;next-mdx&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you look at the code you may notice the absence of a routing coding, a &lt;a href="https://reacttraining.com/react-router/" rel="noopener noreferrer"&gt;react-router&lt;/a&gt; or similar, that’s &lt;strong&gt;NextJS&lt;/strong&gt; in action, it gives an automatic routing system, just put your routes under page folder and the routing is done:&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%2Fi%2F286c0v65mrz3u24nek6i.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%2Fi%2F286c0v65mrz3u24nek6i.png" alt="Routing" width="366" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wondering how does it work and how is that done, check here: &lt;a href="https://nextjs.org/docs/routing/introduction" rel="noopener noreferrer"&gt;https://nextjs.org/docs/routing/introduction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we can clearly see how easy can be set a project with advanced feature just by choosing the right tools, because at the end, the heavy work of a developer is not developing thing and yes choosing the right tools for what we need.&lt;/p&gt;

&lt;p&gt;There is so many nice wheels to be used, why would we create our owns? Let’s grab them and construct our beautiful cars!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>pwa</category>
      <category>react</category>
      <category>ssr</category>
    </item>
    <item>
      <title>Middlewares with react context and hooks</title>
      <dc:creator>Vanderlei Alves da Silva</dc:creator>
      <pubDate>Mon, 07 Oct 2019 07:32:11 +0000</pubDate>
      <link>https://forem.com/vanderleisilva/middlewares-with-react-context-and-hooks-2gm1</link>
      <guid>https://forem.com/vanderleisilva/middlewares-with-react-context-and-hooks-2gm1</guid>
      <description>&lt;p&gt;Continuing the idea explored in the &lt;a href="https://dev.to/vanderleisilva/global-state-management-with-react-hooks-and-context-5f6h"&gt;previous article&lt;/a&gt; of having a global state management using pure react (with react context and hooks), we’re going to explore now how to take advantage of the middlewares concept, implementing for that a loger and localStorage middleware to our todo app, &lt;a href="https://vanderleisilva.github.io/react-context/" rel="noopener noreferrer"&gt;check here the live demo&lt;/a&gt; and &lt;a href="https://github.com/vanderleisilva/react-context/tree/middlewares" rel="noopener noreferrer"&gt;here the source code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  About middlewares
&lt;/h3&gt;

&lt;p&gt;The term can slightly differ from each depending on the middleware type (&lt;em&gt;Database Middleware, Integration Middleware, Application Middleware, Object Middleware, Remote Procedure Call (RPC) Middleware, Message Oriented Middleware ...&lt;/em&gt;) but essentially they have the idea of a composable peace of code running in the middle of to distincts processes improving their communication, and by process we could use more specific terms according to the scenario that we are talking about. &lt;/p&gt;

&lt;p&gt;In the web development niche this term is spreedly used in server side technologies such as &lt;a href="https://laravel.com/docs/6.x/middleware" rel="noopener noreferrer"&gt;Laravel&lt;/a&gt;, &lt;a href="http://expressjs.com/en/guide/using-middleware.html" rel="noopener noreferrer"&gt;ExpressJS&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/middleware" rel="noopener noreferrer"&gt;nestJS&lt;/a&gt; among others as: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A composition of functions that are called, in a given order, before the route handler and that usually each one of them have access to the request information and a reference to the next function in this chain&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This idea was taken by the front-end fellows, mainly applied by the state management libraries: &lt;a href="https://redux.js.org/advanced/middleware" rel="noopener noreferrer"&gt;redux&lt;/a&gt;, &lt;a href="https://github.com/mobxjs/mobx-state-tree/blob/master/docs/middleware.md" rel="noopener noreferrer"&gt;mobx&lt;/a&gt;, &lt;a href="https://vuex.vuejs.org/guide/plugins.html" rel="noopener noreferrer"&gt;vuex&lt;/a&gt; (the last even though with a different nomenclature “plugin” the idea is the same), and what they all do is to provide a way of running some code between dispatching an action, and the moment it changes the application state.&lt;/p&gt;

&lt;p&gt;Of course this concept can be used in other scenarios, this &lt;a href="https://medium.com/@burimshala/how-to-implement-middleware-in-angular-using-ui-router-b3267dddbae8" rel="noopener noreferrer"&gt;article&lt;/a&gt; explores its usage attached to the router change in angular, getting closer to the above mentioned server-side ones. But for now we’re going to explore the first one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Show me the code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;final&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./log&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./localStorage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;final&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;st&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;st&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s all what matters, we need a function to create a middleware chain and execute all them in a given order and of course call our handler (the reducer function called by a given action in our application).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;final&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we define the middlewares that will be called and in which order they will, the ones that comes before &lt;strong&gt;handler&lt;/strong&gt; are the pre-middlewares (you put here all middlewares that you want to run something before the state have changed) and the others the post-middlewares (the ones that execute something with the new state).&lt;/p&gt;

&lt;p&gt;The middleware function signature follows the same pattern of the reducers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;newState&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As an example here is the initial log middlewares:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The middleware just log the initial state (before the state have being change by the reducer) on the console.&lt;/p&gt;

&lt;p&gt;Here we have a more interesting one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;store2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This middleware saves the current state on the local storage, I’m using for this a small library &lt;a href="https://www.npmjs.com/package/store2" rel="noopener noreferrer"&gt;store2&lt;/a&gt; just to make sure retrocompatibility with old browsers and also avoiding working with try catch statements.&lt;/p&gt;

&lt;p&gt;I have on the app state an storeId property with the name of the key that will be saved on the local storage, so basically in this call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I store in the given key the given state. If you &lt;a href="https://vanderleisilva.github.io/react-context/" rel="noopener noreferrer"&gt;check the app again&lt;/a&gt;, play around and refresh the page, the information will still be there.&lt;/p&gt;

&lt;p&gt;And lastly we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;st&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;st&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use the &lt;a href="https://www.w3schools.com/jsref/jsref_reduce.asp" rel="noopener noreferrer"&gt;reduce array method&lt;/a&gt; to iterate over each item of the chain getting the result of the previous and passing to the next item.&lt;/p&gt;

&lt;h3&gt;
  
  
  There it is
&lt;/h3&gt;

&lt;p&gt;We have now returned to the basics and explored how the main state management libraries conceptually work with middlewares, giving us the same results with less dependencies and less complexity. We now understand what happens, instead of just blindly using them.&lt;/p&gt;

&lt;p&gt;What do we got from it!? A better reasoning of when to use these state libraries.&lt;/p&gt;

&lt;p&gt;What do we go from now!? More hooks on the way, check here the new custom hooks from react-router-v5.1 and see you soon. ;)&lt;/p&gt;

&lt;h5&gt;
  
  
  References
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://dev.to/vanderleisilva/global-state-management-with-react-hooks-and-context-5f6h"&gt;https://dev.to/vanderleisilva/global-state-management-with-react-hooks-and-context-5f6h&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vanderleisilva.github.io/react-context/" rel="noopener noreferrer"&gt;https://vanderleisilva.github.io/react-context/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://laravel.com/docs/6.x/middleware" rel="noopener noreferrer"&gt;https://laravel.com/docs/6.x/middleware&lt;/a&gt;&lt;br&gt;
&lt;a href="http://expressjs.com/en/guide/using-middleware.html" rel="noopener noreferrer"&gt;http://expressjs.com/en/guide/using-middleware.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.nestjs.com/middleware" rel="noopener noreferrer"&gt;https://docs.nestjs.com/middleware&lt;/a&gt;&lt;br&gt;
&lt;a href="https://redux.js.org/advanced/middleware" rel="noopener noreferrer"&gt;https://redux.js.org/advanced/middleware&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/mobxjs/mobx-state-tree/blob/master/docs/middleware.md" rel="noopener noreferrer"&gt;https://github.com/mobxjs/mobx-state-tree/blob/master/docs/middleware.md&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vuex.vuejs.org/guide/plugins.html" rel="noopener noreferrer"&gt;https://vuex.vuejs.org/guide/plugins.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/jsref/jsref_reduce.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/jsref/jsref_reduce.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://reacttraining.com/blog/react-router-v5-1/" rel="noopener noreferrer"&gt;https://reacttraining.com/blog/react-router-v5-1/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>middleware</category>
      <category>hooks</category>
    </item>
    <item>
      <title>Global state management with react hooks and context</title>
      <dc:creator>Vanderlei Alves da Silva</dc:creator>
      <pubDate>Tue, 24 Sep 2019 07:33:09 +0000</pubDate>
      <link>https://forem.com/vanderleisilva/global-state-management-with-react-hooks-and-context-5f6h</link>
      <guid>https://forem.com/vanderleisilva/global-state-management-with-react-hooks-and-context-5f6h</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;From prop drilling to centralized global state management with react&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It all started with amazing frameworks like react, vue, angular and some others that have had the brilliant idea of abstracting the application data from the document object model (DOM). React specifically, with your &lt;a href="https://reactjs.org/docs/reconciliation.html" rel="noopener noreferrer"&gt;reconciliation algorithm&lt;/a&gt; and soon with the &lt;a href="https://github.com/acdlite/react-fiber-architecture" rel="noopener noreferrer"&gt;fiber architecture&lt;/a&gt;, rocks on how fast these layers (abstraction and DOM) are updated. With that we can focus on our components instead of the “real” HTML implementations, however from that also come some other new challenges, let’s put it in images:&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%2Frl0lyapq3wuce7j81hkk.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%2Frl0lyapq3wuce7j81hkk.png" alt="Prop drilling" width="680" height="960"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s the classical prop drilling react anti-pattern, the process of going through the react component tree in order to pass properties between them. Higher order components or Decorators, if you are in a more object oriented style, give us more flexibility and some others architectural possibilities. We can now extract away that functionality which we want to share and decorate the components that need use it.&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%2F75oyi4hur7tspiun1aob.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%2F75oyi4hur7tspiun1aob.png" alt="High Order Component" width="767" height="1118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s all fine while dealing with small apps with few components interacting with each other, however when we have complex communication between a vast component ecosystem than this approach starts getting complicated and bug prone. From that reality our unidirectional data flow comes into stage:&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%2Fl1o8tazxgi798nwdeumd.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%2Fl1o8tazxgi798nwdeumd.png" alt="react-redux" width="761" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Until here nothing new, but what if we take the concept and apply it using react context and hooks!? That’s why you here!&lt;/p&gt;

&lt;h3&gt;
  
  
  Main concept
&lt;/h3&gt;

&lt;p&gt;The main highlight by now is our great and new friend &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;react hooks&lt;/a&gt;, and your consequently functional approach:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then the center idea is to use the &lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;context API&lt;/a&gt; together with &lt;a href="https://reactjs.org/docs/hooks-reference.html#usecontext" rel="noopener noreferrer"&gt;useContext&lt;/a&gt; and &lt;a href="https://reactjs.org/docs/hooks-reference.html#usereducer" rel="noopener noreferrer"&gt;useReducer&lt;/a&gt; hooks to make our store available to our components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useReducer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StateContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StoreProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;StateContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;StateContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We export from this file &lt;a href="https://github.com/vanderleisilva/react-context/blob/master/src/store/index.js" rel="noopener noreferrer"&gt;source code here&lt;/a&gt; a &lt;strong&gt;StoreProvider&lt;/strong&gt; (responsible for making the context/store available in the application), that receives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the reducer function with the signature &lt;strong&gt;(state, action) =&amp;gt; newState&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;application initialState;&lt;/li&gt;
&lt;li&gt;and the application content (children);&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the &lt;strong&gt;useStore&lt;/strong&gt; hook that is responsible for getting the data from the store/context.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Even though the nomenclatures are different from now on I’ll reference our context as store, because the concept is the same and we can easily associate to our well known redux architecture standard.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The beauty relies on this simplicity:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;StateContext.Provider&lt;/strong&gt; receives a value object (your current state);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;useReducer&lt;/strong&gt; receives a function: (state, action) =&amp;gt; newState and an initialState  then any dispatch made from our app will pass here and update our application current state;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;useContext&lt;/strong&gt; get our store and make it available in our application!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the rest is just code organization and minor changes, nothing to worry about :)&lt;/p&gt;

&lt;h3&gt;
  
  
  Going into details
&lt;/h3&gt;

&lt;p&gt;As a proof of concept, I’ve done this basic todo list application, &lt;a href="https://github.com/vanderleisilva/react-context" rel="noopener noreferrer"&gt;check here the source code&lt;/a&gt; and &lt;a href="https://vanderleisilva.github.io/react-context/" rel="noopener noreferrer"&gt;here the live implementation&lt;/a&gt;,  it’s a basic interface that contains a couple of component and the current state tree so then we can see the state modifications over the time.  &lt;/p&gt;

&lt;p&gt;The project structure looks like this:&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%2Fxszldg1nv1o73gwcmtmj.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%2Fxszldg1nv1o73gwcmtmj.png" alt="Project folder structure" width="350" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The structure is pretty straightforward (action as we’d normally do in a redux application), I’ve moved the initialState from the reducers, because reducer is about state modification and not definition, besides that the store folder contains the already discussed react context / hooks implementation.&lt;/p&gt;

&lt;p&gt;The reducer file has a quite different design:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./todo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;types&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;actions/types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;handlers&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;handlers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;handlers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;createReducer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ADD_TODO&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REMOVE_TODO&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;UPDATE_TODO&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FILTER_TODO&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SHOW_STATE&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;showState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The point here is just to avoid those huge switch statements usually seen in reducer functions with a mapping object, so basically for every new reducer we just add a new entrance in the mapping object.&lt;/p&gt;

&lt;p&gt;But again, it’s all a matter of implementation the requirement here is that the function needs to have the &lt;strong&gt;(state, action) =&amp;gt; newState&lt;/strong&gt; interface as we’re already used to with Redux.&lt;/p&gt;

&lt;p&gt;And finally but not least our component subscribing to the store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;store&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;filterTodo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;actions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uuid/v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@material-ui/core/Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="nx"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useStore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
    &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filterTodo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;
      &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;variant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contained&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;disabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Add&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What comes next
&lt;/h3&gt;

&lt;p&gt;The next steps will be related to middlewares and type-checking, how do we work here? Technically the middleware is a function called just before the dispatched action reaches the reducer, so the &lt;strong&gt;createReducer&lt;/strong&gt; function above is a great place for that, and what about type-checking!?  Typescript on it! And see you soon! &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cheers!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://github.com/acdlite/react-fiber-architecture" rel="noopener noreferrer"&gt;https://github.com/acdlite/react-fiber-architecture&lt;/a&gt;&lt;br&gt;
&lt;a href="https://reactjs.org/docs/reconciliation.html" rel="noopener noreferrer"&gt;https://reactjs.org/docs/reconciliation.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;https://reactjs.org/docs/hooks-intro.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/vanderleisilva/react-context" rel="noopener noreferrer"&gt;https://github.com/vanderleisilva/react-context&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>redux</category>
    </item>
  </channel>
</rss>
