concept React component in category rxjs

This is an excerpt from Manning's book RxJS in Action.
As we mentioned earlier, React components are just plain functions that get invoked with parameters and return React (virtual HTML) elements, making them pure functions. Sometimes, however, this route is insufficient because you may want to also add event handlers, listen for when a component becomes mounted or attached to the DOM, or apply customizations to the state that’s being passed in; then, you’d end up with very complex function bodies, which defeats the purpose. It’s sometimes necessary for the developer to have more fine-grained control over a component’s lifecycle as well as how it manages its state. React also exposes a mechanism for creating new components that offers more capabilities than a trivial function provides.
Take the standard search engine example you implemented in chapter 5. You learned that standard inputs can be used as event sources for data that comes from, say, keyup events. In the DOM, you could use a query to get the search bar element, attach the corresponding event handlers, and begin listening for events. After the stream is set up, you could begin subscribing to it from other parts of the application. If you were to implement the input box and the output list as React components, then the search results list, located somewhere else on the page, could subscribe to those events and update as new results arrive. But this becomes an issue in a feed-forward (unidirectional) model like React. Why? Remember that state flows smoothest when it’s travelling to child components and not so well when it’s going back upstream and into another isolated component, as shown in figure 10.3.
Figure 10.3. React components for search. Two different React components have no direct way of communicating because each component’s state is completely encapsulated within the component. So you must resort to using external, shared variables or patterns such as an event bus.
![]()
When two isolated components need to communicate, this inevitably leads to sharing state variables, and you end up losing all the benefits of encapsulating state changes into a single downstream pipeline. This is important to understand. As you can see from figure 10.3, React components are good about keeping state to themselves, and it’s meant to flow only downward. Therefore, if you modeled the search bar and the search results widgets as React components, there wouldn’t be a direct way of sharing the data that originates in one with the other. This is a philosophical decision of React that states that components should never know (or care) whether another component is stateless or stateful.