<?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: Óscar Pérez </title>
    <description>The latest articles on DEV Community by Óscar Pérez  (@oscarprdev).</description>
    <link>https://dev.to/oscarprdev</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%2F1133408%2F895aa5f0-6d56-4d1d-bfe4-55730ed8de12.jpeg</url>
      <title>DEV Community: Óscar Pérez </title>
      <link>https://dev.to/oscarprdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oscarprdev"/>
    <language>en</language>
    <item>
      <title>Typescript + Vue linter config step by step</title>
      <dc:creator>Óscar Pérez </dc:creator>
      <pubDate>Thu, 17 Aug 2023 13:58:29 +0000</pubDate>
      <link>https://dev.to/oscarprdev/typescript-vue-linter-config-step-by-step-ni8</link>
      <guid>https://dev.to/oscarprdev/typescript-vue-linter-config-step-by-step-ni8</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION
&lt;/h2&gt;

&lt;p&gt;Configuring a linter with TypeScript might seem daunting if you're unsure where to begin. Fortunately, here's an easy and straightforward method to set up TypeScript for your Vue application.&lt;/p&gt;

&lt;p&gt;In this guide, I'll be using Eslint along with Standard and Prettier. I believe these tools offer a simpler way to kickstart your work without spending excessive time on manual configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  GET'S START
&lt;/h2&gt;

&lt;p&gt;First of all, we'll need install eslint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx eslint --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will be asking you a bunch of things, just follow the installation selecting your preferences.&lt;/p&gt;

&lt;p&gt;In my case, I'd like to use Standard and Typescript.&lt;/p&gt;

&lt;p&gt;Secondly, we need to install prettier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i prettier -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this tools installed we need to configure a bit some files.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONFIG FILES
&lt;/h2&gt;

&lt;p&gt;The first file to configure will be ".prettierrc" following this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
  "arrowParens": "always",
  "semi": true,
  "comma-dangle": ["error", "never"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are my prettier preferences, but they can be whatever you think works fine with your workflow.&lt;/p&gt;

&lt;p&gt;Finally the ".eslintrc.json" file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "env": {
        "browser": true,
        "es2021": true,
        "node": true
    },
    "extends": [
        "standard-with-typescript",
        "plugin:vue/vue3-essential"
    ],
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project": ["./tsconfig.json"],
        "tsconfigRootDir": "./",
        "extraFileExtensions": [".vue"],
        "parser": "@typescript-eslint/parser"
    },

    "plugins": [
        "vue"
    ],
    "rules": {
        "@typescript-eslint/member-delimiter-style": 0,
        "@typescript-eslint/semi": 0,
        "vue/multi-word-component-names": "off",
        "@typescript-eslint/strict-boolean-expressions": 0,
        "@typescript-eslint/no-invalid-void-type": 0
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is pre-configured by you once Eslint is installed, but probably you will need to add some configurations, such as the "rules", "parserOptions" and "extends".&lt;/p&gt;

&lt;h2&gt;
  
  
  FINAL STEP
&lt;/h2&gt;

&lt;p&gt;Once we already have everything configured, our last step will be create an script to re-format all our code in a simple way. This is my favourite easy script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"format": "prettier --write \"{,!(node_modules)/**/}*.{js,jsx}\""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way only running this script all your code will be pretty formated :)&lt;/p&gt;

&lt;h2&gt;
  
  
  ENJOY
&lt;/h2&gt;

&lt;p&gt;Well, this is my personal Eslint and prettier configuration, I know it can be improved a lot, so just share your feedback on comments. I'm more than happy to learn better ways to configure a project with Typescript and a proper formatter tool.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>vue</category>
      <category>typescript</category>
      <category>learning</category>
    </item>
    <item>
      <title>Intersection observer api &amp; lazy loading in REACT</title>
      <dc:creator>Óscar Pérez </dc:creator>
      <pubDate>Sat, 05 Aug 2023 07:35:03 +0000</pubDate>
      <link>https://dev.to/oscarprdev/intersection-observer-api-lazy-loading-in-react-44</link>
      <guid>https://dev.to/oscarprdev/intersection-observer-api-lazy-loading-in-react-44</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION
&lt;/h2&gt;

&lt;p&gt;Let's embark on an exciting journey to control how our app behaves as the user scrolls and ensure our components only render when they are in the user's view. And to top it off, we want to achieve this in a lazy loading fashion!&lt;/p&gt;

&lt;p&gt;Introducing the &lt;strong&gt;&lt;em&gt;Lazy Component Wrapper&lt;/em&gt;&lt;/strong&gt; - a simple guide to achieving this seamlessly. Let's dive in and experience the magic of lazy rendering! &lt;/p&gt;

&lt;h2&gt;
  
  
  LAZY COMPONENT WRAPPER
&lt;/h2&gt;

&lt;p&gt;This component will render the children component only when it becomes visible to the user. By using the Intersection Observer API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function LazyComponentWrapper({ children, className, id }: LazyComponentWrapperProps) {
    const [isVisible, setIsVisible] = useState(false);
    const componentRef = useRef&amp;lt;HTMLElement | null&amp;gt;(null);

    useEffect(() =&amp;gt; {
        const observer = new IntersectionObserver(
            (entries) =&amp;gt; {
                entries.forEach((entry) =&amp;gt; {
                    if (entry.isIntersecting) {
                        setIsVisible(true);
                        observer.unobserve(entry.target);
                    }
                });
            },
            { threshold: 0.5 } as IntersectionObserverInit
        );

        if (componentRef.current) {
            observer.observe(componentRef.current!);
        }

        return () =&amp;gt; {
            if (componentRef.current) {
                observer.unobserve(componentRef.current!);
            }
        };
    }, []);

    return (
        &amp;lt;section
            ref={componentRef}
            className={`${className} ${isVisible ? styles.visible : styles.notVisible}`}
            id={id}&amp;gt;
            {isVisible &amp;amp;&amp;amp; children}
        &amp;lt;/section&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not only does this component enable lazy rendering, but it also allows us to add captivating animations and styles to animate the components as they appear on the user's screen. And to achieve this enchanting effect, we'll make use of CSS modules!.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.visible {
    opacity: 1;
    transform: translateY(0);
    transition: all 0.5s ease-in-out;
}

.notVisible {
    opacity: 0;
    transform: translateY(80px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  LAZY IMPORTS AND SUSPENSE
&lt;/h2&gt;

&lt;p&gt;Finally, let's import our components and wrap them with our magnificent &lt;strong&gt;&lt;em&gt;LazyComponentWrapper&lt;/em&gt;&lt;/strong&gt;:✨&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Component = lazy(() =&amp;gt; import("../../Component.tsx"));

&amp;lt;LazyComponentWrapper&amp;gt;
   &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
      &amp;lt;Component /&amp;gt;
   &amp;lt;/Suspense&amp;gt;
&amp;lt;/LazyComponentWrapper&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your component will render only when the user needs it, thanks to the use of lazy loading and the Intersection Observer API. &lt;/p&gt;

&lt;p&gt;Additionally, adding specific styles with CSS modules adds an extra touch of charm to the user experience.&lt;/p&gt;

&lt;p&gt;Happy coding! ✨🚀&lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/oscarprdev"&gt;@oscarprdev&lt;/a&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>learning</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Frontend state management with clean architecture</title>
      <dc:creator>Óscar Pérez </dc:creator>
      <pubDate>Sat, 05 Aug 2023 07:15:26 +0000</pubDate>
      <link>https://dev.to/oscarprdev/frontend-state-management-with-clean-architecture-22d8</link>
      <guid>https://dev.to/oscarprdev/frontend-state-management-with-clean-architecture-22d8</guid>
      <description>&lt;ol&gt;
&lt;li&gt;
## &lt;strong&gt;INTRODUCTION&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of the most critical aspects of developing a client-side application is how we handle global state management.&lt;/p&gt;

&lt;p&gt;Many developers spend hours and hours searching for the perfect tool: Redux, Akita, Pinia, Ngrx, Context, Vuex... But the truth is, if we aim for code that is agnostic and truly maintainable over time, we cannot simply delegate the core piece of our applications to external libraries or tools whose future maintenance is uncertain.&lt;/p&gt;

&lt;p&gt;That's where clean architecture comes to the rescue, advising us to separate the domain or core components of our application from those parts that are likely to change over time. In other words, tools and frameworks should never directly manage any piece of the global state of our application.&lt;/p&gt;

&lt;p&gt;So, I've taken the initiative to create this post and share my step-by-step solution on how to handle global domain state in a client-side application using Typescript and Object-Oriented Programming (OOP). &lt;/p&gt;

&lt;p&gt;Let's begin! 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;REACTIVITY&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When it comes to managing global state, we need it to be reactive to any changes that occur within it. Therefore, if we are going to build a global state handler, reactivity should be our top priority.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let's create an abstract class that will solely take care of managing the global state with reactivity:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export abstract class UseCase&amp;lt;S&amp;gt; {
    public state: S;
    private listeners: Subscription&amp;lt;S&amp;gt;[] = [];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will name the class &lt;strong&gt;&lt;em&gt;UseCase&lt;/em&gt;&lt;/strong&gt;, and it will have two properties: &lt;strong&gt;&lt;em&gt;state&lt;/em&gt;&lt;/strong&gt; and &lt;em&gt;&lt;strong&gt;listeners&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;state will be responsible for holding the global state, while listeners will handle reactivity.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Our class will include a &lt;strong&gt;&lt;em&gt;constructor&lt;/em&gt;&lt;/strong&gt; that receives the state of the feature extending the use case:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    constructor(initialState: S) {
        this.state = initialState;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Methods:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first method of this class will be the one that allows us to execute any use case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract execute(value?: any): void
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Absolutely right! The first method should be abstract so that the extending class can handle any logic, such as calling an API to fetch information.&lt;/p&gt;

&lt;p&gt;On the other hand, we also need a method to retrieve the state when required:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    getState(): S {
        return this.state;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exactly! We need another method to update the state. This will allow us to modify the global state when necessary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    updateState(newState: Partial&amp;lt;S&amp;gt;): void {
        this.state = {
            ...this.state,
            ...newState,
        };
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, here comes the magic where reactivity occurs intuitively and easy to understand.&lt;/p&gt;

&lt;p&gt;We'll add a small piece of code to the &lt;strong&gt;&lt;em&gt;updateState&lt;/em&gt;&lt;/strong&gt; method that will execute any method found in the &lt;strong&gt;&lt;em&gt;listeners&lt;/em&gt;&lt;/strong&gt; property we created earlier. &lt;/p&gt;

&lt;p&gt;Here's how the &lt;strong&gt;&lt;em&gt;updateState&lt;/em&gt;&lt;/strong&gt; method would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    updateState(newState: Partial&amp;lt;S&amp;gt;): void {
        this.state = {
            ...this.state,
            ...newState,
        };

        if (this.listeners.length) {
            this.listeners.forEach((listener) =&amp;gt; listener(this.state));
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, every time we want to update the state, it will trigger a function to which we'll pass the updated state as an argument. &lt;/p&gt;

&lt;p&gt;This will enable &lt;strong&gt;&lt;em&gt;reactivity&lt;/em&gt;&lt;/strong&gt; as any listeners registered with the listeners property will be notified and can react accordingly to the changes in the &lt;strong&gt;&lt;em&gt;global state&lt;/em&gt;&lt;/strong&gt;. This approach simplifies the handling of reactivity and makes it intuitive and easy to manage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listener(this.state)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make the listeners property functional, we need to introduce the methods we want it to execute. We'll achieve this by adding another method called &lt;strong&gt;&lt;em&gt;subscribe&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   subscribe(listener: Subscription&amp;lt;S&amp;gt;) {
        this.listeners.push(listener);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The subscribe method will allow us to add methods to the listeners property so that they can be executed when the state is updated. This way, we can dynamically register functions to react to state changes in our application.&lt;/p&gt;

&lt;p&gt;Shall you guess which method we could pass to this &lt;strong&gt;&lt;em&gt;subscribe&lt;/em&gt;&lt;/strong&gt; method? 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CUSTOM HOOK&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Exactly! Now that we have our abstract class, we can use it anywhere in our code. But how do we connect our fancy framework to our previous code? &lt;/p&gt;

&lt;p&gt;Well, there can be numerous solutions from here on, and it all depends on the specific framework we're using.&lt;/p&gt;

&lt;p&gt;For this example, let's dive into React and create a &lt;strong&gt;&lt;em&gt;custom hook&lt;/em&gt;&lt;/strong&gt;! Why not make it fun and enjoy the magic of connecting everything smoothly?:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function useSubscription&amp;lt;S, U extends UseCase&amp;lt;S&amp;gt;&amp;gt;(useCase: U, setStateFn: Dispatch&amp;lt;SetStateAction&amp;lt;S&amp;gt;&amp;gt;) {
    useCase.execute();
    useCase.subscribe((state) =&amp;gt; setStateFn((prevState) =&amp;gt; ({ ...prevState, ...state })));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;&lt;em&gt;useSubscription&lt;/em&gt;&lt;/strong&gt; custom hook allows us to call the execute method, which can, for instance, make API calls, and we can also use the subscribe method to pass a function that updates the state of our components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setStateFn((prevState) =&amp;gt; ({ ...prevState, ...state }))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this magical &lt;strong&gt;&lt;em&gt;useSubscription&lt;/em&gt;&lt;/strong&gt; custom hook, we can seamlessly connect our abstract class to React components and enjoy the wonders of reactivity! Now, every state update will trigger the registered functions, ensuring our components stay in sync with the global state. Isn't this a delightful way to handle state management? Let the fun begin!. 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;IMPLEMENTATION&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we've reached this point, let's see how we implement this custom hook in our &lt;strong&gt;&lt;em&gt;React&lt;/em&gt;&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;Imagine an application for recipes, and our component wants to fetch recipes from the database. With React, we'd do something similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [listRecipes, setListRecipes] = useState&amp;lt;ListRecipesUseCaseState&amp;gt;(listRecipesUseCase.getState())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll use useState to manage the state of recipe lists, and we'll initiate it by calling the API with the method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listRecipesUseCase.getState()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once again, you got it! Following this, let's use &lt;strong&gt;&lt;em&gt;useEffect&lt;/em&gt;&lt;/strong&gt; to subscribe to our global state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt; {
        useSubscription&amp;lt;ListRecipesUseCaseState, ListRecipesUseCase&amp;gt;(listRecipesUseCase, setListRecipes);
    }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the &lt;strong&gt;&lt;em&gt;useEffect&lt;/em&gt;&lt;/strong&gt;, our component will subscribe to the global state changes, ensuring it stays in sync with any updates that occur. Now, our recipe app is all set to whip up a delightful user experience!😋&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;SVELTE EXAMPLE&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Fantastic! To wrap it up, let's illustrate the same implementation, this time using &lt;strong&gt;&lt;em&gt;Svelte&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;In Svelte, we'll create a &lt;strong&gt;&lt;em&gt;store&lt;/em&gt;&lt;/strong&gt; that exposes a method called &lt;strong&gt;&lt;em&gt;setAppState&lt;/em&gt;&lt;/strong&gt;, which will update the state using the &lt;strong&gt;&lt;em&gt;appState.set(state)&lt;/em&gt;&lt;/strong&gt; function. :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const appState = writable(stateUseCase.state, () =&amp;gt;
  stateUseCase.setDefaultState(books)
)

export const setAppState = (state: GlobalState) =&amp;gt; {
  appState.set(state)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use this approach, we'll call the &lt;strong&gt;&lt;em&gt;subscribe&lt;/em&gt;&lt;/strong&gt; method in our &lt;strong&gt;&lt;em&gt;App.svelte&lt;/em&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Here's how it would look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;beforeUpdate(() =&amp;gt; {
    stateUseCase.subscribe(setAppState)
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, our app will automatically subscribe and update the global state every time we call &lt;strong&gt;&lt;em&gt;updateState&lt;/em&gt;&lt;/strong&gt; in our use cases. It creates a seamless and &lt;strong&gt;&lt;em&gt;reactive experience&lt;/em&gt;&lt;/strong&gt;, keeping our app in sync with the &lt;strong&gt;&lt;em&gt;global state&lt;/em&gt;&lt;/strong&gt; effortlessly&lt;/p&gt;

&lt;p&gt;Thank you for joining me on this journey! I hope this has been helpful, and I look forward to your feedback.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/oscarprdev"&gt;@oscarprdev&lt;/a&gt; 🚀🌟&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>cleancode</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
