<?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: Julian Schäfer</title>
    <description>The latest articles on DEV Community by Julian Schäfer (@theiaz).</description>
    <link>https://dev.to/theiaz</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%2F318197%2F62e2a421-abb8-4b18-8607-4b300ff7010b.jpg</url>
      <title>DEV Community: Julian Schäfer</title>
      <link>https://dev.to/theiaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theiaz"/>
    <language>en</language>
    <item>
      <title># The difference between progressive and partial hydration</title>
      <dc:creator>Julian Schäfer</dc:creator>
      <pubDate>Mon, 24 Oct 2022 19:08:18 +0000</pubDate>
      <link>https://dev.to/theiaz/-the-difference-between-progressive-and-partial-hydration-18dd</link>
      <guid>https://dev.to/theiaz/-the-difference-between-progressive-and-partial-hydration-18dd</guid>
      <description>&lt;p&gt;TL;DR: Progressive Hydration is about the &lt;em&gt;WHEN&lt;/em&gt;, Partial Hydration is about the &lt;em&gt;WHAT&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For some time I'm trying to understand the whole thing about rendering patterns. Hydration is a big part of it. The internet is full of articles and tutorials about hydration and how to implement it. But there are fewer about what it really is and how to distinguish between the different types of hydration.&lt;/p&gt;

&lt;p&gt;This article won't go into depth because there is other great content out there. Some of the best was created by &lt;a href="https://twitter.com/RyanCarniato" rel="noopener noreferrer"&gt;ryansolid&lt;/a&gt;. However, I would like to give a quick note to someone who is trying to understand the whole thing about hydration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hydration
&lt;/h2&gt;

&lt;p&gt;Hydration is the process bringing a app which is rendered by the server into the same state as it was rendered by the client. This involves work to download javascript, attach eventlisteners to the correct DOM nodes and recover state on the client side. This work comes at cost. Bandwidth is needed to transfer the data within the javascript to your client. CPU time for parsing and running javascript. All of this may slow your app. In the worst case users needs to deal with the "uncanny valley" effect, where the app seems like it is ready, but hydration isn't finished yet, and therefore it's not yet interactive. &lt;/p&gt;

&lt;p&gt;To mitigate this issues there are several approaches to optimize hydration. I would like to explain two of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Progressive hydration
&lt;/h2&gt;

&lt;p&gt;The first is progressive hydration, which tries to reduce the amount of data which is sent to the client for bootstrapping your application. Instead of fully hydrating your app at once, only chunks of data are sent to the client and parts are hydrated. Those parts may be hydrated if a special event is triggered like clicking a button or if a component comes into the viewport. Your app is &lt;del&gt;building-up&lt;/del&gt; hydrating up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Partial hydration
&lt;/h2&gt;

&lt;p&gt;In comparison, partial hydration uses knowledge about the structure of your application. You as a developer or perhaps a smart compiler, knows which part of your application is always static or requires javascript. This knowledge can be used to determine which parts of your application need to be hydrated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0minndnkonhqu54vszf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0minndnkonhqu54vszf.png" alt="Image description" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at it from an exaggerated point of view, you could take spacetime as an analogy. Progressive hydration is the &lt;em&gt;WHEN&lt;/em&gt;, represented as time axis. Partial hydration is about &lt;em&gt;WHAT&lt;/em&gt; part in your application should be hydrated. Its like describing somewhats position onto the space axis. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note, that I do not think getting much range with this post and it was a quick type. Therefore, some parts could be improved. If something needs to be corrected let me know in the comments :)&lt;/em&gt; &lt;/p&gt;

</description>
      <category>hydration</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Vue - an appwide error notification system</title>
      <dc:creator>Julian Schäfer</dc:creator>
      <pubDate>Fri, 22 Apr 2022 12:00:37 +0000</pubDate>
      <link>https://dev.to/theiaz/vue-an-appwide-error-notification-system-pa6</link>
      <guid>https://dev.to/theiaz/vue-an-appwide-error-notification-system-pa6</guid>
      <description>&lt;p&gt;User notifications are important to communicate feedback to the user. They need to be meaningful and descriptive. Most of the time they are triggered by an action. These actions can have different origins like an user input or scheduled jobs and are placed all over the app. &lt;/p&gt;

&lt;p&gt;In this post I want to show you our approach to implement an appwide error notification system within vue. The special thing is, that &lt;strong&gt;all notifications can be triggered above the whole app and are handled in one place&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To follow the steps have a look at the little &lt;a href="https://codesandbox.io/s/appwide-error-notifications-fi5xnl?file=/src/i18n/index.js" rel="noopener noreferrer"&gt;demo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/appwide-error-notifications-fi5xnl"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The demo explained
&lt;/h2&gt;

&lt;p&gt;As you can see, this simple vue app consists of two child components, &lt;code&gt;Pizza.vue&lt;/code&gt; and &lt;code&gt;Pasta.vue&lt;/code&gt; which acts as our "business" components. Next to them is the &lt;code&gt;Notification.vue&lt;/code&gt; component, which is responsible to display error notifications. &lt;strong&gt;In real applications there would be many more "business" components or even page components, deeply nested in each other. All of them may need trigger an action and inform the user if something unexpected happen.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo demonstrates a common usecase, where a business action is triggered from a user by pressing a button. This action starts an API call which may fail. If so, the user needs feedback. In this example, the call always fails.  &lt;/p&gt;

&lt;p&gt;For simplicity a mocked API response is used. It has some additional information for the frontend, like an error code and optional data. The response is wrapped to a custom error called &lt;code&gt;ApiError&lt;/code&gt;.&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="c1"&gt;// api.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
  &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
  &lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
  &lt;span class="na"&gt;json&lt;/span&gt;&lt;span class="p"&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;errorCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;INVALID_PIZZA_ID&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;errorData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;  
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&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;msg&lt;/span&gt; &lt;span class="o"&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: Error fetching pizza with ids '&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApiError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorData&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;As a developer you need to decide how you want to handle this failing API request.&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="c1"&gt;// Pizza.vue&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getPizza&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// show a user notification&lt;/span&gt;
   &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserNotificationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="c1"&gt;// do not show a user notification and do some other exception handling&lt;/span&gt;
   &lt;span class="c1"&gt;// throw e&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes it is necessary to notify the user, but not always. Maybe its enough to do something else, like logging the error. &lt;/p&gt;

&lt;p&gt;However, if you decided to notify the user, we need to transform our &lt;code&gt;ApiError&lt;/code&gt; into an &lt;code&gt;UserNotificationError&lt;/code&gt;. Its purpose is to &lt;strong&gt;separate the concerns between UI and API layer&lt;/strong&gt;. Therefore, it wraps all of the data given in &lt;code&gt;ApiError&lt;/code&gt; and bubbles up the component tree. If there is no need to notify the user, we simply could rethrow the &lt;code&gt;ApiError&lt;/code&gt; or handle it otherwise.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;errorCaptured&lt;/code&gt; lifecycle
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;UserNotificationError&lt;/code&gt; will be catched in the upper most component &lt;code&gt;App.vue&lt;/code&gt; within the &lt;a href="https://vuejs.org/api/options-lifecycle.html#errorcaptured" rel="noopener noreferrer"&gt;&lt;code&gt;errorCaptured&lt;/code&gt;&lt;/a&gt; lifecycle hook. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;I did not know this hook, cause all of the lifecycle pictures you see in the vue docs, does not contain it. As a side note, keep an eye on the API docs!&lt;/em&gt;&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="nf"&gt;errorCaptured&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
 &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;UserNotificationError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The docs itself says that this hook is &lt;em&gt;"Called when an error propagating from a descendent component has been captured"&lt;/em&gt;. Hence, our &lt;code&gt;UserNotificationError&lt;/code&gt; will be catched aswell. If we want to display a notification, we only need to filter for this type or error and enrich our &lt;code&gt;error&lt;/code&gt; data property inside &lt;code&gt;App.vue&lt;/code&gt; with the information of &lt;code&gt;UserNotificationError&lt;/code&gt;. As soon as the value changes, the watcher inside &lt;code&gt;Notification.vue&lt;/code&gt; triggers and displays the notification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meaningful notification messages
&lt;/h2&gt;

&lt;p&gt;Now we got a global notification system, so we might think we are done? Wrong! I would recommend one last step. &lt;/p&gt;

&lt;p&gt;For now, we never used the error information of the API response. It could be possible that our API response message is not that detailed or does not support the languages our frontend supports. Therefore, it is recommended (see &lt;a href="https://stackoverflow.com/questions/67290510/whether-all-error-messages-should-come-from-the-backend-in-a-form-that-can-be-sh/67290755#67290755" rel="noopener noreferrer"&gt;here&lt;/a&gt; or &lt;a href="https://stackoverflow.com/questions/30109787/internationalization-of-api-error-messages-on-front-end-or-back-end/45350006#45350006" rel="noopener noreferrer"&gt;here&lt;/a&gt;) to use those error information and enrich client side messages with them.&lt;/p&gt;

&lt;p&gt;In this example I used &lt;a href="https://vue-i18n.intlify.dev/" rel="noopener noreferrer"&gt;vue-i18n&lt;/a&gt; to localize the notification messages. To do so, we only need to use the &lt;code&gt;errorCode&lt;/code&gt; as a key for our localized messages strings and pass the additional error data (like the id) as parameters.&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;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;en&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;apiError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;INVALID_PIZZA_ID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No Pizza with Id {id} could be found.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;INVALID_PASTA_ID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No Pasta with Id {id} could be found.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;errorCaptured&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
 &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;UserNotificationError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`message.apiError.&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorCode&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="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorData&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="kc"&gt;false&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it. Now we have a simple error notification system where all notifications are handled in one place, the top-level component. Also, we didn't use the API error notification. Instead, we gave the frontend code the ability to use its most appropriate message texts and localize them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my second article. I would like to welcome any &lt;br&gt;
suggestions for improvement, feedback, or pointers to false claims.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@californong?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Nong V&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/error?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>ux</category>
    </item>
    <item>
      <title>Explained: Passing props to data - Why is my data not changing?</title>
      <dc:creator>Julian Schäfer</dc:creator>
      <pubDate>Fri, 18 Mar 2022 12:41:45 +0000</pubDate>
      <link>https://dev.to/theiaz/explained-passing-props-to-data-why-is-my-data-not-changing-3d5d</link>
      <guid>https://dev.to/theiaz/explained-passing-props-to-data-why-is-my-data-not-changing-3d5d</guid>
      <description>&lt;p&gt;Today I found out something basic that I should have known for a long time. The value for a &lt;code&gt;data&lt;/code&gt;-property, associated with a &lt;code&gt;props&lt;/code&gt;-property, is only set when the component is initialized! Further changes to the prop will not be applied to the &lt;code&gt;data&lt;/code&gt;-property. &lt;/p&gt;

&lt;h2&gt;
  
  
  An example
&lt;/h2&gt;

&lt;p&gt;Lets assume we've got the following child component, which gets some name passed by its parent.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Child.vue&lt;/code&gt;:&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 {
  name: 'Child',
  props: {
    name: String,
  },
  data() {
    return {
      localName: this.name,
    };
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A parent component can simple pass a name to this component. The initial data value inside &lt;code&gt;Child&lt;/code&gt; is set to name, which is defined inside parent. &lt;/p&gt;

&lt;h3&gt;
  
  
  Runtime types with pass-by-value
&lt;/h3&gt;

&lt;p&gt;I have always thought that this connection &lt;code&gt;localName: this.name&lt;/code&gt; is &lt;em&gt;passed by reference&lt;/em&gt;. So if you change the prop, you also change the &lt;code&gt;data&lt;/code&gt; &lt;em&gt;each time&lt;/em&gt;. &lt;strong&gt;But this is wrong!&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Rather, it is &lt;em&gt;passed by value&lt;/em&gt;, which means the value of &lt;code&gt;this.name&lt;/code&gt; is copied and applied to &lt;code&gt;localName&lt;/code&gt;. Therefore, only the &lt;em&gt;initial value&lt;/em&gt; of &lt;code&gt;this.name&lt;/code&gt; is applied to &lt;code&gt;localName&lt;/code&gt; during rendering time of the component.  Further changes are ignored unless the component is re-rendered. &lt;/p&gt;

&lt;p&gt;This applies to all normal &lt;code&gt;props&lt;/code&gt;-types like &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;Number&lt;/code&gt;, or &lt;code&gt;Boolean&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;Object&lt;/code&gt; are different
&lt;/h3&gt;

&lt;p&gt;This could be the end of the article. However, there exists an exception. &lt;/p&gt;

&lt;p&gt;Arrays and objects are &lt;em&gt;passed by reference&lt;/em&gt;. So it is actually possible to mutate nested properties of the array or the object. Even if it is possible, you should not do it. For more information have a look at the official &lt;a href="https://vuejs.org/guide/components/props.html#one-way-data-flow" rel="noopener noreferrer"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;I've also made an &lt;a href="https://stackblitz.com/edit/vue-vrnnnu?file=src/App.vue" rel="noopener noreferrer"&gt;interactive example&lt;/a&gt; which demonstrates the behaviour of changing &lt;code&gt;props&lt;/code&gt; and how it affects its related &lt;code&gt;data&lt;/code&gt; property..&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Keep this in mind if you change data in your parent component and it does not affect the local state of your child component.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my first article, so I would like to welcome any suggestions for improvement, feedback, or pointers to false claims.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
