<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam L Barrett</title>
    <description>The latest articles on DEV Community by Adam L Barrett (@bigab).</description>
    <link>https://dev.to/bigab</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%2F55851%2Fab4f8738-3186-4f13-bd38-aa66866da518.jpeg</url>
      <title>DEV Community: Adam L Barrett</title>
      <link>https://dev.to/bigab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bigab"/>
    <language>en</language>
    <item>
      <title>A Tale of Two Apps</title>
      <dc:creator>Adam L Barrett</dc:creator>
      <pubDate>Tue, 29 Dec 2020 19:52:39 +0000</pubDate>
      <link>https://dev.to/bigab/a-tale-of-two-apps-2nae</link>
      <guid>https://dev.to/bigab/a-tale-of-two-apps-2nae</guid>
      <description>&lt;p&gt;There are 2 ways to think about the web application you're working on.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In truth there are way more than 2, but this article is about 2 particular ways and how they are different.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The difference is subtle and a bit nefarious because the idea is more philosophical than technical, but can have damaging effects when 2 or more members of the same team view their application differently.&lt;/p&gt;

&lt;p&gt;Personally, I find it very frustrating when articles drag on like some sort of mystery novel, yammering about this and that until they finally get to the “big reveal” of what the article is actually about, and in my first draft of this article I found that’s exactly what I did, so with the power of editing, allow me to start off by describing the 2 ways to think about your web application:&lt;/p&gt;

&lt;h3&gt;
  
  
  #1: the &lt;strong&gt;Interface Model&lt;/strong&gt; application
&lt;/h3&gt;

&lt;p&gt;In this mental model, the application is generally thought of as “on the server” (regardless of what architecture that server is built on) and the web portion of that application is the &lt;strong&gt;User Interface (UI)&lt;/strong&gt; or “view” of that application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W2UzXp02--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bugj9u3n4l0motuc94i0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W2UzXp02--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bugj9u3n4l0motuc94i0.png" alt="graphic of a database, server, and computer monitor with the server in the center" title="Interface Model" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would say this is often the “traditional” perspective taken by developers, especially those who did not start their careers in front-end development, though with all things of course there are exceptions. Storage is most often within databases of one kind or another, with decisions and business logic in server side code, sometimes exposing API interfaces such as RESTful APIs or GraphQL and other times web pages by serving HTML from URL endpoints.&lt;/p&gt;

&lt;h3&gt;
  
  
  #2: the &lt;strong&gt;Distributed Model&lt;/strong&gt; application
&lt;/h3&gt;

&lt;p&gt;In the distributed mental model, the client-side &lt;em&gt;is&lt;/em&gt; the application.  The RESTful and GraphQL APIs serve to support the application with services such as storage, aggregation and heavy calculation, but decisions, state management and UI are handled in the app, on the users device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Gd-uia2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cqra681gde782ju0slw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Gd-uia2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cqra681gde782ju0slw6.png" alt="a graphic with the monitor in the center and a database and server symbol squished off to the side" title="Distributed Model" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is not to be confused with the narrow definition of distributed apps (dApps) running on top of a blockchain, smart contracts or peer-to-peer (P2P) networks, this is still just referring to web applications even if they have centralized authority and storage, but distributed in the sense that the application is intended to run on many machines independently, with both the benefits and detriments that entails.&lt;/p&gt;

&lt;p&gt;This is often how native mobile developers model their thinking, and due to the rise of Single Page Apps (SPAs) on the web, has been a common perspective in web developers for many years now as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what’s the problem...?
&lt;/h3&gt;

&lt;p&gt;As mentioned before, this difference is subtle and is not based on the technology or framework, but instead it is more like a philosophy or a framework for your mind. It can be so subtle in fact that 2 members of the same team, working on the same codebase, can find themselves viewing the app differently in this regard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This can lead to issues.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the mental models of the application on a team are not aligned in this way, the problems often manifest themselves as criticism of “over engineering”, snarky remarks, hostile guffaws about “doing it wrong” and the &lt;em&gt;far more insidious&lt;/em&gt; manifestation: assuming your co-worker “just doesn’t really know what they are doing”.&lt;/p&gt;

&lt;p&gt;Sometimes, this can lead to wasted time, as developers debate and argue over technology choices. Sometimes it can grow worse as bolder developers change the work of others because "that should run on the server" or some other point of view. And sometimes, just sometimes, it can lead to conflict and the breakdown of trust on a team.&lt;/p&gt;

&lt;p&gt;By clearly defining and documenting if your application is using an &lt;strong&gt;Interface Model&lt;/strong&gt; or a &lt;strong&gt;Distributed Model&lt;/strong&gt;, you can circumvent these issues, and it can even add another dimension to evaluate technology choices on, as some tech may feel more or less appropriate depending on your applications model choice.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;If you are working on an &lt;strong&gt;interface model application&lt;/strong&gt;, state management libraries such as &lt;a href="https://redux.js.org/"&gt;Redux&lt;/a&gt;, &lt;a href="https://ngrx.io/"&gt;NgRx&lt;/a&gt;, even &lt;a href="https://mobx.js.org/"&gt;MobX&lt;/a&gt; and others may seem like overkill, because you're not really working with your application state, you are working with a &lt;strong&gt;local cache&lt;/strong&gt; of the application state.&lt;/p&gt;

&lt;p&gt;I think the big feelings of great joy and gratitude that gushed forth across the intertubes when libraries like &lt;a href="https://recoiljs.org/"&gt;Recoil&lt;/a&gt;, &lt;a href="https://swr.vercel.app/"&gt;SWR&lt;/a&gt; and the wicked-smaht &lt;a href="https://react-query.tanstack.com/devtools"&gt;React-Query&lt;/a&gt;, hit the mainstream, were directly from the idea that their concepts fit the mental model of an &lt;strong&gt;interface model application&lt;/strong&gt; better.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/g_abud/why-i-quit-redux-1knl"&gt;Why I Stopped Using Redux&lt;/a&gt; is a great article, and the author is thinking about applications in the &lt;strong&gt;Interface Model&lt;/strong&gt; and yet, immediately in the comments I see people responding who are thinking in terms of the &lt;strong&gt;Distributed Model&lt;/strong&gt;. But without the framework or language to differentiate, they assume the author is “wrong” and tend to conflate the breakdown with complexity or scale, which seems to baffle other commenters who are thinking in terms of the &lt;strong&gt;Interface Model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the article &lt;a href="https://epicreact.dev/my-state-management-mistake"&gt;My State Management Mistake&lt;/a&gt;, Kent C Dodds laments confusing "server cache" with UI state (the stuff that disappears when you hit refresh), and though I wholeheartedly agree in the difference, I think the article is very slanted towards the  &lt;strong&gt;Interface Model&lt;/strong&gt; and the same problem could be dealt with, also by separating the business domain data and the UI state on the client, if you were building with the &lt;strong&gt;Distributed Model&lt;/strong&gt; in mind.&lt;/p&gt;

&lt;p&gt;In a &lt;strong&gt;Distributed Model app&lt;/strong&gt;, that’s not “just the cache” you’re working with, that is your apps current data and state. The GraphQL and RESTful API’s just serve their role of storage, aggregation and a service for heavy calculations, so, what may seem like over-engineering your server cache, may seem perfectly reasonable in the &lt;em&gt;distributed&lt;/em&gt; context.&lt;/p&gt;

&lt;p&gt;For a long time now, since the rise of SPAs, the &lt;strong&gt;Distributed Model&lt;/strong&gt; was very popular in modern web development. Even when many developers expressed the idea we had strayed too far from traditional web apps “just for some fancy animations and transitions”, there continued to be litany of state management libraries released specifically for handling all your application needs right in the client.&lt;/p&gt;

&lt;p&gt;But, the tides are certainly changing now, and with the rise of “island architecture” frameworks, like Remix, Hotwire, and others the pendulum is swinging back towards the &lt;strong&gt;Interface Model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And that server-ward swing got punched into overdrive when &lt;a href="https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html"&gt;Dan Abramov and Lauren Tan announced the upcoming React Server Components&lt;/a&gt;. Because they, and the rest of the React team, hold such an incredible amount of sway in JavaScript community, and have a tendency to deliver features that change the entire ecosystem, beyond just React, and despite warning and a plead to not jump in too early, a new mob of developers will be psyched, and start evangelizing Server Components as “the new way to write web apps”.&lt;/p&gt;

&lt;p&gt;Soon, every other framework will be pummelled with issues and demands for “server components” of their own. Arrogant gatekeepers and well-meaning “JavaScript influencers” will begin to proclaim we are “doing it wrong” if we don't include an accompanying Node.js app filled with the magic of streaming DOM updates hidden behind the familiar React component interface.  ...and to be honest, I am a little psyched myself.&lt;/p&gt;

&lt;p&gt;But there is still a place for the &lt;strong&gt;distributed model&lt;/strong&gt; in web applications.&lt;/p&gt;

&lt;p&gt;If, for example, your team consists of mostly front-end developers who are comfortable with client side technology, that’s probably reason enough to work in the &lt;strong&gt;distributed mode&lt;/strong&gt;l. The right tool for the job adage definitely includes the skills your team currently have.&lt;/p&gt;

&lt;p&gt;You may also have an app that could make the jump to a &lt;code&gt;dApp&lt;/code&gt;, built on &lt;a href="https://ethereum.org/"&gt;Ethereum&lt;/a&gt; or some other distributed system, removed from centralization, and starting your app in the &lt;strong&gt;distributed model&lt;/strong&gt; may better prepare you for that jump.&lt;/p&gt;

&lt;p&gt;Maybe one of your app's primary features is offline use, and if a good portion of your app can be used without a network connection, that may be a strong indicator that the distributed model may be more appropriate.&lt;/p&gt;

&lt;p&gt;It may also be that your app is simple in its data requirements, and differentiates itself with design and interactions, and treating the app as an &lt;strong&gt;interface model&lt;/strong&gt; application just doesn’t feel right.&lt;/p&gt;

&lt;p&gt;And maybe you want to minimize your server costs and security concerns, so you’re leaning full Jamstack, pushing your app to edge CDNs and leveraging cloud services like &lt;a href="https://auth0.com/"&gt;Auth0&lt;/a&gt; and &lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt; to handle the parts you just don’t want to deal with.&lt;/p&gt;

&lt;p&gt;Conversely, using any technology that blurs the line between client and server is probably a good sign that the &lt;strong&gt;Interface Model&lt;/strong&gt; is more appropriate for your application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  If your application implements an RPC (remote procedure call) API&lt;/li&gt;
&lt;li&gt;  React’s upcoming Server Side Components&lt;/li&gt;
&lt;li&gt;  Tools like Blazor (C#) or Flutter (Dart)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;...or similar technologies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So in closing, my advice is this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Decide and document which mental model you are designing your app with. Evaluate your tech stack and see if alternatives may seem more appropriate with that decision in mind. Ensure every new developer onboarded to the team is also informed whether your app is built on the &lt;strong&gt;interface model&lt;/strong&gt; or the &lt;strong&gt;distributed model&lt;/strong&gt;. Stop assuming people don’t know what they are doing, and rather, see if you can understand how they are thinking.&lt;/p&gt;

&lt;p&gt;That last one is pretty good advice in general.&lt;/p&gt;

</description>
      <category>web</category>
      <category>webdev</category>
      <category>application</category>
      <category>development</category>
    </item>
    <item>
      <title>RxJS with React: Actions and Subjects</title>
      <dc:creator>Adam L Barrett</dc:creator>
      <pubDate>Mon, 31 Aug 2020 04:13:15 +0000</pubDate>
      <link>https://dev.to/bigab/rxjs-with-react-actions-and-subjects-3e5j</link>
      <guid>https://dev.to/bigab/rxjs-with-react-actions-and-subjects-3e5j</guid>
      <description>&lt;p&gt;RxJS and React go together like chocolate and peanut butter: great individually but they become something incredible when put together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MAuH5cM8TOkt5dt6w6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MAuH5cM8TOkt5dt6w6/giphy.gif" alt="Chocolate and Peanut Butter Accidents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Actions
&lt;/h3&gt;

&lt;p&gt;So in &lt;a href="https://dev.to/bitovi/rxjs-with-react-jek"&gt;the last article&lt;/a&gt;, we looked at how you can use the React built-in hooks &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; to subscribe to RxJS Observables. We created a custom &lt;code&gt;useObservable&lt;/code&gt; hook that we can pass an RxJS Observable to, which will return the current value of the Observable and re-render every time the value changes.&lt;/p&gt;

&lt;p&gt;In the React community, there used to be a lot more talk about the concept of Data Down and Actions Up (DDAU). With our &lt;code&gt;useObservable&lt;/code&gt; custom hook, we've got the "data down" part cased, so now we need to handle the &lt;strong&gt;actions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What are &lt;strong&gt;actions&lt;/strong&gt; anyway?&lt;/p&gt;

&lt;p&gt;Nowadays, there are 2 meanings to what we call React &lt;strong&gt;actions&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The original meaning, which was just about passing functions (callbacks) as props to communicate with your parent component. There is no 2-way binding in React, so if the child component wants to tell its parent component someone clicked a button or changed an input, it calls a function that was passed to it as a prop, which is sometimes known as the delegate pattern. &lt;strong&gt;Actions&lt;/strong&gt; are just the act of calling those delegate prop functions (callbacks), like &lt;code&gt;onChange&lt;/code&gt; or &lt;code&gt;onPause&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redux popularized a new meaning for &lt;strong&gt;actions&lt;/strong&gt; though. In Redux, actions are serializable objects that describe the interaction or intent of the user. Conventionally they have a &lt;code&gt;type&lt;/code&gt; property, and optional &lt;code&gt;payload&lt;/code&gt; and &lt;code&gt;meta&lt;/code&gt; properties as well. The &lt;strong&gt;action&lt;/strong&gt; objects are &lt;em&gt;&lt;strong&gt;dispatched&lt;/strong&gt;&lt;/em&gt; into the Redux store by calling the store's &lt;code&gt;dispatch()&lt;/code&gt; method, and passing the &lt;strong&gt;action&lt;/strong&gt; object as an argument.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But whether &lt;strong&gt;actions&lt;/strong&gt; are the act of calling a delegate callback function, or an object describing the intent passed to a &lt;code&gt;dispatch&lt;/code&gt; call, it still represents the idea that "something happened", and I would like to &lt;em&gt;send a message&lt;/em&gt; to my parent component, the store, or whatever, describing what happened.&lt;/p&gt;

&lt;h3&gt;
  
  
  Subjects
&lt;/h3&gt;

&lt;p&gt;RxJS &lt;a href="https://rxjs.dev/api/index/class/Subject" rel="noopener noreferrer"&gt;Subjects&lt;/a&gt; are a great fit for dispatching actions. &lt;code&gt;Subjects&lt;/code&gt; are special Observables that can also act as &lt;strong&gt;observers&lt;/strong&gt;, because they implement the &lt;code&gt;observer&lt;/code&gt; interface, which is just a fancy way of saying it has the methods &lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;error()&lt;/code&gt;, and &lt;code&gt;complete()&lt;/code&gt;. You can dispatch &lt;strong&gt;actions&lt;/strong&gt; by calling a subject's &lt;code&gt;.next()&lt;/code&gt; method, and passing whatever description of the event you need as an argument: Whatever argument we pass to &lt;code&gt;.next()&lt;/code&gt; is emitted to all the subject's &lt;strong&gt;observers&lt;/strong&gt;, sometimes called subscribers.&lt;/p&gt;

&lt;p&gt;We can use RxJS's &lt;code&gt;Subject&lt;/code&gt; to implement something like a Redux store. We can derive our &lt;code&gt;State&lt;/code&gt; observable, as a combination of the current state, and an &lt;strong&gt;observable of actions&lt;/strong&gt; which we get from using our Action &lt;code&gt;Subject&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To get a clearer picture of what that means, let's use the simple &lt;code&gt;useObservable&lt;/code&gt; custom hook we wrote in &lt;a href="https://dev.to/bitovi/rxjs-with-react-jek"&gt;Part 1&lt;/a&gt; to create a simple count widget.&lt;/p&gt;

&lt;p&gt;We'll create an observable of state (count), out the observable of actions + the current state:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// this will be an observable of `increment` or `decrement` strings&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;action$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// map the action strings to a state update number&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;update$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;action$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;map&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;action&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// update the state by summing the state and the update&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;update$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;startWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// our initial state will be 0&lt;/span&gt;
  &lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;count&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;...and a widget component that uses the &lt;code&gt;count$&lt;/code&gt; observable and the custom &lt;code&gt;useObservable&lt;/code&gt; hook to get a &lt;code&gt;count&lt;/code&gt; state, and also uses the &lt;code&gt;action$&lt;/code&gt; Subject to update the state by passing &lt;code&gt;increment&lt;/code&gt; or &lt;code&gt;decrement&lt;/code&gt; actions to the &lt;code&gt;action$.next()&lt;/code&gt; method.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CountWidget&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useObservable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count$&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"count-widget"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;action$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;decrement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;-&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;action$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;p&gt;Here is the simple demo of the above.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/uou9x"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This is simplistic but the idea can be expanded to something more useful. If we combine the same technique with our User Name Fetcher from &lt;a href="https://dev.to/bitovi/rxjs-with-react-jek"&gt;Part 1&lt;/a&gt;, we could easily add a paging feature to give the user the ability to navigate through a list of items. We create a callback function that takes an Observable of the &lt;code&gt;'back'&lt;/code&gt; and &lt;code&gt;'forward'&lt;/code&gt; actions dispatched in our component, and based on that, it fetches new "pages" of users, by increasing or decreasing the &lt;code&gt;page&lt;/code&gt; query parameter in the API call.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/fz3kp"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Though the example is a little more involved, the idea is the same, create an observable of "page number" which is derived from the actions, and use the &lt;code&gt;page$&lt;/code&gt; observable to derive the list of names from an API call.&lt;/p&gt;
&lt;h3&gt;
  
  
  Something like &lt;code&gt;useReducer&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;One of the nice aspects of the React built-in hook &lt;a href="https://reactjs.org/docs/hooks-reference.html#usereducer" rel="noopener noreferrer"&gt;&lt;code&gt;useReducer&lt;/code&gt;&lt;/a&gt; is that you can define the reducer outside of the component. You can test the reducer function independently, and you know when you pass it to &lt;code&gt;useReducer&lt;/code&gt; React will just update the state and re-render the component automatically.&lt;/p&gt;

&lt;p&gt;Let's change our &lt;code&gt;useObservable&lt;/code&gt; hook to have the same qualities.&lt;/p&gt;

&lt;p&gt;To achieve this, we will alter our &lt;code&gt;useObservable&lt;/code&gt; hook to take a function instead. The function passed to &lt;code&gt;useObservable&lt;/code&gt; will receive an &lt;strong&gt;Observable of actions&lt;/strong&gt; (the actions we dispatch from the component) as an argument, and will be expected to return an Observable of our new state. We’ll model the API for our custom hook after&lt;code&gt;useReducer()&lt;/code&gt;, so it will return a tuple of&lt;br&gt;&lt;br&gt;
&lt;code&gt;[state, dispatch]&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
This way, we can leave it up to the developer how they want to respond to the dispatched actions and how it will affect the state.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;useObservable&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="c1"&gt;// let the developer decide how the action$ Observable affects the state&lt;/span&gt;
  &lt;span class="nx"&gt;actions$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* … */&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// returns an observable that emits the new state&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;newState$&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;So to implement our new &lt;code&gt;useObservable()&lt;/code&gt; custom hook we will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;take a callback function &lt;code&gt;fn&lt;/code&gt; as an argument;&lt;/li&gt;
&lt;li&gt;create an RxJS &lt;code&gt;Subject&lt;/code&gt; as our &lt;code&gt;action$&lt;/code&gt; observable;&lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;dispatch&lt;/code&gt; function that passes it's argument to &lt;code&gt;action.next()&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;state$&lt;/code&gt; Observable by calling the &lt;code&gt;fn&lt;/code&gt; callback and passing the &lt;code&gt;action$&lt;/code&gt; as an argument&lt;/li&gt;
&lt;li&gt;pull the &lt;code&gt;state&lt;/code&gt; out of the &lt;code&gt;state$&lt;/code&gt; observable using the same &lt;code&gt;useState&lt;/code&gt;/&lt;code&gt;useEffect&lt;/code&gt; technique as before&lt;/li&gt;
&lt;li&gt;return the new &lt;code&gt;state&lt;/code&gt; and the &lt;code&gt;dispatch&lt;/code&gt; function as a &lt;code&gt;[state, dispatch]&lt;/code&gt; tuple&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With that we end up with something like this:&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;useObservable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&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="c1"&gt;// create the action$ observable only 1 time&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;action$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// the dipatch function is memoized with useCallback()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;v&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;action$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&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="c1"&gt;// store the callback on a ref, ignoring any new callback values&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;current&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;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&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="c1"&gt;// use the callback to create the new state$ observable&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state$&lt;/span&gt; &lt;span class="o"&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;action$&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;sub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setState&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;gt;&lt;/span&gt; &lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&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="nx"&gt;action$&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="nx"&gt;state&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="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This looks a little like &lt;code&gt;useReducer&lt;/code&gt; now, except that while &lt;code&gt;useReducer&lt;/code&gt; is limited to synchronous updates to state, our &lt;code&gt;useObservable&lt;/code&gt; can update state over time. Also, our &lt;code&gt;useObservable&lt;/code&gt; is a safe async-hook, because it unsubscribes on clean-up, so you don’t have to worry about updating a components state after it has been unmounted.&lt;/p&gt;
&lt;h4&gt;
  
  
  Updating the example
&lt;/h4&gt;

&lt;p&gt;Now, with that in place, we can define a &lt;code&gt;getUserNames()&lt;/code&gt; function that follows our expected &lt;code&gt;useObservable&lt;/code&gt; interface. Our &lt;code&gt;getUserNames()&lt;/code&gt; function can be separate, isolated from our component. We can test it independently and, in theory, use the same functionality in different components. We'll extract the name fetching functionality into its own file and export the function &lt;code&gt;getUserNames&lt;/code&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startWith&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;switchMap&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="s2"&gt;rxjs/operators&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;ajax&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="s2"&gt;rxjs/ajax&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;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://randomuser.me/api/?results=5&amp;amp;seed=rx-react&amp;amp;nat=us&amp;amp;inc=name&amp;amp;noinfo`&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;getName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;getUserNames&lt;/span&gt; &lt;span class="o"&gt;=&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actionMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;back&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&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;page$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;action$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;page&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;page&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;actionMap&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;startWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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;page$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;switchMap&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;page&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;ajax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;page=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;results&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;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getName&lt;/span&gt;&lt;span class="p"&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;Then our component would import &lt;code&gt;getUserNames&lt;/code&gt; and along with our new &lt;code&gt;useObservable&lt;/code&gt; and look something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&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;names&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;useObservable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getUserNames&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;RxJS with React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;back&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;⇦&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;forward&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;⇨&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;p&gt;Here is the example in full:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/d0hjy"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I think this is a really nice pattern: it is obvious what the component does, the presentation is decoupled from how the data is actually retrieved, it follows the flux pattern, and generally aligns nicely with React model of component state and side effects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cOB8cDnKM6eyY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cOB8cDnKM6eyY/giphy.gif" alt="Cheering"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;This is really just scratching the surface though, our &lt;code&gt;useObservable&lt;/code&gt; hook could be improved in many ways, including exposing the current state to the callback function, using memoization and other techniques to improve the performance, and offering some way to allow component props/state to be exposed to the callback function as a stream of props.&lt;/p&gt;

&lt;p&gt;If you'd like to see a more robust implementation of these ideas, you can check out my &lt;a href="https://github.com/BigAB/use-epic" rel="noopener noreferrer"&gt;use-epic&lt;/a&gt; library on GitHub which follows a very similar pattern.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/BigAB" rel="noopener noreferrer"&gt;
        BigAB
      &lt;/a&gt; / &lt;a href="https://github.com/BigAB/use-epic" rel="noopener noreferrer"&gt;
        use-epic
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Use RxJS Epics as state management for your React Components
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;There is so much more that could be done when mixing React with RxJS: Animations, real-time updates, entity stores... the list goes on and on. If you'd be interested in any of those topics, let me know in the comments.&lt;/p&gt;

</description>
      <category>rxjs</category>
      <category>react</category>
      <category>hooks</category>
      <category>observables</category>
    </item>
    <item>
      <title>RxJS with React</title>
      <dc:creator>Adam L Barrett</dc:creator>
      <pubDate>Thu, 10 Oct 2019 23:49:40 +0000</pubDate>
      <link>https://dev.to/bitovi/rxjs-with-react-jek</link>
      <guid>https://dev.to/bitovi/rxjs-with-react-jek</guid>
      <description>&lt;p&gt;RxJS and React go together like chocolate and peanut butter: great individually but they become something incredible when put together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwjfugclfqoikgb64ezq9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwjfugclfqoikgb64ezq9.gif" alt="2 people colliding and accidentally mixing their chocolate bar and peanut butter, but then seemingly enjoying the mix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A quick search on npm will find a slew of hooks to connect RxJS Observables to React components, but let’s start at the beginning, because RxJS and React fit very well together &lt;em&gt;"as is"&lt;/em&gt; because they follow the same philosophy and have very compatible APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  A quick aside about Why RxJS
&lt;/h3&gt;

&lt;p&gt;2019 has been the year of RxJS, blowing up across the web-dev community with events like &lt;a href="https://www.rxjs.live/" rel="noopener noreferrer"&gt;rxjs.live&lt;/a&gt; and &lt;a href="https://www.ng-conf.org/" rel="noopener noreferrer"&gt;ng-conf&lt;/a&gt;. More and more developers are finding out that RxJS is awesome and it is totally worth climbing your way through the somewhat steep learning curve.&lt;/p&gt;

&lt;p&gt;Angular devs have been using RxJS for a while now. A quick search will find vue-rx, ember-rx, and even Svelte can use RxJS Observables as stores by default. When you learn RxJS you are learning a highly portable skill that can be used across frameworks. The concepts of Rx can actually be used across languages and platforms.&lt;/p&gt;

&lt;p&gt;RxJS is a mature, battle hardened library for dealing with events and data flow. It is definitely going to be valuable to familiarize yourself with how it works.&lt;/p&gt;




&lt;p&gt;Let’s start with a simple example:&lt;/p&gt;

&lt;p&gt;We’ve got a simple &lt;code&gt;List&lt;/code&gt; component here that just lists the strings it is given:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Adam&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="s1"&gt;Brian&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="s1"&gt;Christine&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&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;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setNames&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;source&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;RxJS with React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;p&gt;&lt;iframe src="https://codesandbox.io/embed/6f7bw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(follow along on CodeSandbox!)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s pull those values from an RxJS Observable.&lt;/p&gt;

&lt;p&gt;Let’s start by creating an Observable with the RxJS &lt;a href="https://rxjs.dev/api/index/function/of" rel="noopener noreferrer"&gt;&lt;code&gt;of()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;

&lt;p&gt;We'll need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add &lt;code&gt;rxjs&lt;/code&gt; as a dependency &lt;em&gt;(&lt;code&gt;npm i rxjs&lt;/code&gt;, &lt;code&gt;yarn add rxjs&lt;/code&gt; or however you need to if you're not using CodeSandbox)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;import &lt;code&gt;of&lt;/code&gt; from &lt;code&gt;rxjs&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then let's create an Observable called &lt;code&gt;names$&lt;/code&gt;, whose value is the &lt;code&gt;source&lt;/code&gt; array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;of&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;rxjs&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;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Adam&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="s1"&gt;Brian&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="s1"&gt;Christine&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;names$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;FYI:&lt;/strong&gt; &lt;em&gt;I will be following the convention of naming an Observable variable with a \$ suffix (aka &lt;a href="https://medium.com/@benlesh/observables-and-finnish-notation-df8356ed1c9b" rel="noopener noreferrer"&gt;Finnish Notation&lt;/a&gt;), which is completely optional but I think it may help for clarity while learning.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now what we want to do is &lt;strong&gt;synchronize the component state with the state from the Observable&lt;/strong&gt;. This would be considered a &lt;strong&gt;side-effect&lt;/strong&gt; of the React function component &lt;code&gt;App&lt;/code&gt;, so we are going to use the &lt;a href="https://reactjs.org/docs/hooks-effect.html" rel="noopener noreferrer"&gt;&lt;code&gt;useEffect()&lt;/code&gt;&lt;/a&gt; hook, which we can import from &lt;code&gt;react&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;useEffect()&lt;/code&gt; callback we will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;subscribe to the &lt;code&gt;names$&lt;/code&gt; Observable with the &lt;code&gt;subscribe()&lt;/code&gt; method, passing our "state setter function" &lt;code&gt;setNames&lt;/code&gt; as the &lt;strong&gt;observer&lt;/strong&gt; argument&lt;/li&gt;
&lt;li&gt;capture the &lt;code&gt;subscription&lt;/code&gt; returned from &lt;code&gt;observable.subscribe()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;return a clean-up function that calls the subscriptions &lt;code&gt;.unsubscribe()&lt;/code&gt; method
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&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;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setNames&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&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;subscription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;names$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setNames&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;gt;&lt;/span&gt; &lt;span class="nx"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsubscribe&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;RxJS with React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;p&gt;Which at this point should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/ox99d"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The concepts and APIs in RxJS and React are very compatible: the way &lt;code&gt;useEffect&lt;/code&gt; aligns with an RxJS subscription and how the clean-up call is a perfect time to unsubscribe. You’ll see a lot more of that "symbiosis" as we go on.&lt;/p&gt;

&lt;h3&gt;
  
  
  An aside about &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;When using &lt;code&gt;useEffect&lt;/code&gt; to synchronize component state to some "outer" state, you must decide what state you want to sync with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All state&lt;/li&gt;
&lt;li&gt;No state&lt;/li&gt;
&lt;li&gt;Some select pieces of state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is represented in the &lt;code&gt;deps&lt;/code&gt; array, which is the &lt;strong&gt;second argument&lt;/strong&gt; passed to &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To use an quote from Ryan Florence:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1125041041063665666-773" src="https://platform.twitter.com/embed/Tweet.html?id=1125041041063665666"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1125041041063665666-773');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1125041041063665666&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;useEffect(fn) // all state&lt;/code&gt;&lt;br&gt;
&lt;code&gt;useEffect(fn, []) // no state&lt;/code&gt;&lt;br&gt;
&lt;code&gt;useEffect(fn, [these, states])&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, in this instance we don't have any props or other state to sync with: we just want our names array to be whatever is the current value of our Observable. We just want to update our component state whenever the Observables value changes, so we’ll go with &lt;strong&gt;No State&lt;/strong&gt; and throw in an empty array &lt;code&gt;[]&lt;/code&gt; as the second argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&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;subscription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;names$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setNames&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;gt;&lt;/span&gt; &lt;span class="nx"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&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;
  
  
  Creating a custom hook
&lt;/h3&gt;

&lt;p&gt;It looks like we'll be using this pattern a lot:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;subscribing to an Observable in &lt;code&gt;useEffect&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;setting the state on any changes&lt;/li&gt;
&lt;li&gt;unsubscribing in the clean-up function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;...so let’s extract that behaviour into a &lt;strong&gt;custom hook&lt;/strong&gt; called &lt;code&gt;useObservable&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useObservable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;observable&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;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&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;sub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;observable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setState&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;gt;&lt;/span&gt; &lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;observable&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;Our &lt;code&gt;useObservable&lt;/code&gt; hook takes an Observable and returns the last emitted value of that Observable, while causing a re-render on changes by calling &lt;code&gt;setState&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note that our state is initialized as &lt;code&gt;undefined&lt;/code&gt; until some value is emitted in the Observable. We'll use that later, but for now, make sure the components can handle when the &lt;code&gt;state&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So we should have something like this now:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/3qpvw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Of course, we could, &lt;em&gt;and probably should&lt;/em&gt;, have &lt;code&gt;useObservable()&lt;/code&gt; defined as an export from a module in its own file because it is shareable across components and maybe even across apps. But for our simple example today, we'll just keep everything in one file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding some asynchronicity
&lt;/h3&gt;

&lt;p&gt;So we’ve got this list of names showing now, but this is all very boring so far, so let’s do something a little more &lt;strong&gt;Asynchronous&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s import &lt;code&gt;interval&lt;/code&gt; from &lt;code&gt;rxjs&lt;/code&gt; and the &lt;code&gt;map&lt;/code&gt; operator from &lt;code&gt;rxjs/operators&lt;/code&gt;. Then, let's use them to create on Observable that only adds a name to the list every second.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;interval&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;rxjs&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;map&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;rxjs/operators&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;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Adam&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="s1"&gt;Brian&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="s1"&gt;Christine&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;names$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/7xxyc?runonclick=1"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Neat. So we can see our list appearing one at a time. Sort of useless, but off to a good start. 😄&lt;/p&gt;

&lt;h3&gt;
  
  
  Fetching some data
&lt;/h3&gt;

&lt;p&gt;Instead of our &lt;code&gt;source&lt;/code&gt; array, let’s fetch the list of names from an API.&lt;/p&gt;

&lt;p&gt;The API endpoint we’ll be using comes from &lt;a href="https://randomuser.me/" rel="noopener noreferrer"&gt;randomuser.me&lt;/a&gt;, which is a nice service for just getting some made up user data.&lt;/p&gt;

&lt;p&gt;We’ll add these 2 helper variables, &lt;code&gt;api&lt;/code&gt; and &lt;code&gt;getName&lt;/code&gt; which will allow us to fetch 5 users at a time and the function will help extract the name from the user data randomuser.me provides.&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;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://randomuser.me/api/?results=5&amp;amp;seed=rx-react&amp;amp;nat=us&amp;amp;inc=name&amp;amp;noinfo`&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;getName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://rxjs.dev/" rel="noopener noreferrer"&gt;RxJS&lt;/a&gt; has some great utility functions for fetching data such as &lt;code&gt;fromFetch&lt;/code&gt; and &lt;code&gt;webSocket&lt;/code&gt;, but since we are just getting some JSON from an ajax request, we’ll be using the RxJS &lt;code&gt;ajax.getJSON&lt;/code&gt; method from the &lt;code&gt;rxjs/ajax&lt;/code&gt; module.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ajax&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;rxjs/ajax&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;names$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ajax&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="na"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;users&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;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will fetch the first 5 users from the API and map over the array to extract the name from the &lt;code&gt;name.first&lt;/code&gt; and &lt;code&gt;name.last&lt;/code&gt; property on each user. Now our component is rendering the 5 names from the API, yay!&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/1gcbf"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;It's interesting to note here, that since we moved our code into a custom hook, we haven't changed the component code at all. When you decouple the data from the display of the component like this, you get certain advantages. For example, we could hook up our Observable to a websocket for live data updates, or even do polling in a web-worker, but the component doesn't need to change, it is happy rendering whatever data it is given and the implementation of how the data is retrieved is isolated from the display on the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aside about RxJS Ajax
&lt;/h3&gt;

&lt;p&gt;One of the great benefits of using the RxJS &lt;a href="https://rxjs.dev/api/ajax/ajax" rel="noopener noreferrer"&gt;ajax module&lt;/a&gt; (as well as &lt;a href="https://rxjs.dev/api/fetch/fromFetch" rel="noopener noreferrer"&gt;fromFetch&lt;/a&gt;), is that &lt;strong&gt;request cancellation&lt;/strong&gt; is built right in.&lt;/p&gt;

&lt;p&gt;Because our &lt;code&gt;useObservable&lt;/code&gt; hook unsubscribes from the Observable in the clean-up function, if our component was ever “unmounted” while an ajax request was in flight, the ajax request would be cancelled and the &lt;code&gt;setState&lt;/code&gt; would never be called. It is a great memory safe feature built in without needing any extra effort. RxJS and React working great together, out of the box, again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fp66hp5q76bckyjj9velo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fp66hp5q76bckyjj9velo.jpg" alt="Reese's Peanut Butter Cups"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Actions
&lt;/h3&gt;

&lt;p&gt;So now we have this great custom hook for reading state values off an Observable. Those values can come from anywhere, asynchronously, into our component, and that is pretty good, but React is all about Data Down and Actions Up (DDAU). We’ve really only got the data half of that covered right now, what about the &lt;strong&gt;actions&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;In the next instalment of the series we'll explore &lt;strong&gt;Actions&lt;/strong&gt;, how we model our RxJS integration after the built-in useReducer hook, and much much more.&lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to post in the comments, or you can join our Bitovi community Slack at &lt;a href="https://bitovi.com/community/slack" rel="noopener noreferrer"&gt;https://bitovi.com/community/slack&lt;/a&gt;, and ask me directly. There are lots of other JavaScript experts there too, and it is a great place to ask questions or get some help.&lt;/p&gt;

</description>
      <category>rxjs</category>
      <category>react</category>
      <category>hooks</category>
    </item>
  </channel>
</rss>
