<?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: jmoreno</title>
    <description>The latest articles on DEV Community by jmoreno (@jmoreno).</description>
    <link>https://dev.to/jmoreno</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%2F763478%2Fd8f01172-58ff-497f-84e4-590117e67d50.jpg</url>
      <title>DEV Community: jmoreno</title>
      <link>https://dev.to/jmoreno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jmoreno"/>
    <language>en</language>
    <item>
      <title>Sharing React Query State Across Astro Islands</title>
      <dc:creator>jmoreno</dc:creator>
      <pubDate>Sat, 01 Mar 2025 13:08:59 +0000</pubDate>
      <link>https://dev.to/jmoreno/sharing-react-query-state-across-astro-islands-3g5i</link>
      <guid>https://dev.to/jmoreno/sharing-react-query-state-across-astro-islands-3g5i</guid>
      <description>&lt;h2&gt;
  
  
  Thinking about Astro Islands
&lt;/h2&gt;

&lt;p&gt;When working with Astro's island architecture, each React component is isolated from others. This creates a challenge when you need to share state between components, especially when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple components need access to the same data&lt;/li&gt;
&lt;li&gt;Components need to stay in sync with each other&lt;/li&gt;
&lt;li&gt;You want to avoid redundant API calls&lt;/li&gt;
&lt;li&gt;You need to maintain a consistent UI state across the page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional React patterns like lifting state up or using a global context provider don't work well in this environment because each island has its own React tree.&lt;/p&gt;

&lt;p&gt;The main insight here is around &lt;em&gt;how JavaScript modules are executed&lt;/em&gt; in the browser. When Astro builds your site:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Each island becomes its own bundle with its dependencies&lt;/li&gt;
&lt;li&gt;If multiple islands import the same module (let's call it &lt;code&gt;shared.js&lt;/code&gt;), that module will be:

&lt;ul&gt;
&lt;li&gt;Included in the dependency graph for each island&lt;/li&gt;
&lt;li&gt;But executed only once when the first island loads it&lt;/li&gt;
&lt;li&gt;Subsequent islands will use the already initialized instance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This execution order guarantee is the key that makes sharing state possible. If we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Island A → imports → shared.js (with QueryClient)
Island B → imports → shared.js (with QueryClient)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the browser loads these islands, &lt;code&gt;shared.js&lt;/code&gt; will be executed before either island's code runs. This means the singleton QueryClient will be initialized once and then available for all islands to access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why React Query is a Perfect Fit
&lt;/h2&gt;

&lt;p&gt;Taking step back let's see why React Query is a great choice for this problem.&lt;/p&gt;

&lt;p&gt;React Query offers several advantages that make it ideal:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cache-based architecture&lt;/strong&gt; : React Query's core is a cache that can be shared&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic deduplication&lt;/strong&gt; : Identical queries automatically share data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stale-while-revalidate pattern&lt;/strong&gt; : Components always show something while refreshing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configurable staleness&lt;/strong&gt; : Control when data needs refreshing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Built-in prefetching&lt;/strong&gt; : Load data before it's needed&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Let's implement a complete example with a todo application that has multiple components needing access to the same data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import type { ComponentType, ReactNode } from "react";

// Create a singleton QueryClient that will be shared across all components
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 1000 * 60 * 5, // 5 minutes
      refetchOnWindowFocus: false,
    },
  },
});

/**
 * Higher-order component that wraps a component with a QueryClientProvider
 * using a shared QueryClient instance.
 *
 * This is useful for Astro islands where you need isolated contexts
 * but want to share the same query client.
 *
 * @param Component - The component to wrap
 * @returns A new component wrapped with QueryClientProvider
 */
export function withQuery&amp;lt;P extends object&amp;gt;(
  Component: ComponentType&amp;lt;P&amp;gt;,
): ComponentType&amp;lt;P&amp;gt; {
  // The display name for the wrapped component
  const displayName = Component.displayName || Component.name || "Component";

  // The wrapped component
  const WithQuery = (props: P) =&amp;gt; {
    const { children, ...componentProps } = props as P &amp;amp; {
      children?: ReactNode;
    };

    return (
      &amp;lt;QueryClientProvider client={queryClient}&amp;gt;
        &amp;lt;Component {...(componentProps as P)}&amp;gt;{children}&amp;lt;/Component&amp;gt;
      &amp;lt;/QueryClientProvider&amp;gt;
    );
  };

  // Set the display name for better debugging
  WithQuery.displayName = `withQuery(${displayName})`;

  return WithQuery;
}

// Export the queryClient in case it needs to be accessed directly
export { queryClient };

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the Pattern in Practice
&lt;/h2&gt;

&lt;p&gt;Now let's use this withQuery hook to share fetched API data between our islands. In our first TodoList file we want to display our Todo items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/lib/todo-api.ts
export interface Todo {
  id: number;
  title: string;
  completed: boolean;
}

// src/components/TodoList.tsx
import { useQuery } from "@tanstack/react-query";
import { fetchTodos, Todo } from "../lib/todo-api";
import { withQuery } from "../lib/with-query";

function TodoList() {
  const { data, isLoading, error } = useQuery({
    queryKey: ["todos"],
    queryFn: fetchTodos,
  });

  if (isLoading) return &amp;lt;div&amp;gt;Loading todos...&amp;lt;/div&amp;gt;;
  if (error) return &amp;lt;div&amp;gt;Error loading todos&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;ul className="todo-list"&amp;gt;
      {data?.map((todo) =&amp;gt; (
        &amp;lt;li key={todo.id} className={todo.completed ? "completed" : ""}&amp;gt;
          {todo.title}
        &amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
}

export default withQuery(TodoList);

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

&lt;/div&gt;



&lt;p&gt;In our TodoStats we're using that same query to derive some quick stats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/components/TodoStats.tsx
import { useQuery } from "@tanstack/react-query";
import { fetchTodos } from "../lib/todo-api";
import { withQuery } from "../lib/with-query";

function TodoStats() {
  const { data, isLoading } = useQuery({
    queryKey: ["todos"],
    queryFn: fetchTodos,
  });

  if (isLoading) return &amp;lt;div&amp;gt;Loading stats...&amp;lt;/div&amp;gt;;

  const totalTodos = data?.length || 0;
  const completedTodos = data?.filter((todo) =&amp;gt; todo.completed).length || 0;
  const percentComplete =
    totalTodos &amp;gt; 0 ? Math.round((completedTodos / totalTodos) * 100) : 0;

  return (
    &amp;lt;div className="todo-stats"&amp;gt;
      &amp;lt;h3&amp;gt;Todo Statistics&amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;Total todos: {totalTodos}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Completed: {completedTodos}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Completion rate: {percentComplete}%&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default withQuery(TodoStats);

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

&lt;/div&gt;



&lt;p&gt;Finally we need a form to actually create our Todos. Here we're invalidating the singleton queryClient cache when we finish our mutation.&lt;/p&gt;

&lt;p&gt;Because our components share this single queryClient instance this will cause them to update with new data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/components/TodoForm.tsx
import { useMutation } from "@tanstack/react-query";
import { useState } from "react";
import { updateTodo } from "../lib/todo-api";
import { withQuery } from "../lib/with-query";
import { queryClient } from "../lib/query-client";

function TodoForm() {
  const [todoId, setTodoId] = useState("");
  const [title, setTitle] = useState("");

  const mutation = useMutation({
    mutationFn: updateTodo,
    onSuccess: () =&amp;gt; {
      // Invalidate the todos query to trigger a refetch
      queryClient.invalidateQueries({ queryKey: ["todos"] });
      // Reset form
      setTodoId("");
      setTitle("");
    },
  });

  const handleSubmit = (e: React.FormEvent) =&amp;gt; {
    e.preventDefault();
    if (!todoId || !title) return;

    mutation.mutate({
      id: parseInt(todoId),
      title,
      completed: false,
    });
  };

  return (
    &amp;lt;form onSubmit={handleSubmit} className="todo-form"&amp;gt;
      &amp;lt;h3&amp;gt;Update Todo&amp;lt;/h3&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label htmlFor="todoId"&amp;gt;Todo ID:&amp;lt;/label&amp;gt;
        &amp;lt;input
          id="todoId"
          type="number"
          value={todoId}
          onChange={(e) =&amp;gt; setTodoId(e.target.value)}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label htmlFor="title"&amp;gt;New Title:&amp;lt;/label&amp;gt;
        &amp;lt;input
          id="title"
          type="text"
          value={title}
          onChange={(e) =&amp;gt; setTitle(e.target.value)}
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;button type="submit" disabled={mutation.isPending}&amp;gt;
        {mutation.isPending ? "Updating..." : "Update Todo"}
      &amp;lt;/button&amp;gt;
      {mutation.isError &amp;amp;&amp;amp; (
        &amp;lt;p className="error"&amp;gt;Error: {mutation.error.message}&amp;lt;/p&amp;gt;
      )}
      {mutation.isSuccess &amp;amp;&amp;amp; (
        &amp;lt;p className="success"&amp;gt;Todo updated successfully!&amp;lt;/p&amp;gt;
      )}
    &amp;lt;/form&amp;gt;
  );
}

export default withQuery(TodoForm);

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using in Astro Templates
&lt;/h2&gt;

&lt;p&gt;Now we can use these components in our Astro templates. Note the &lt;code&gt;client:load&lt;/code&gt; this tells Astro that it should ship the javascript bundle to the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
// src/pages/todos.astro
import TodoList from "../components/TodoList";
import TodoStats from "../components/TodoStats";
import TodoForm from "../components/TodoForm";
---

&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Todo Application&amp;lt;/title&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1" /&amp;gt;
    &amp;lt;link rel="stylesheet" href="/styles/global.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;Todo Application&amp;lt;/h1&amp;gt;

      &amp;lt;div class="todo-container"&amp;gt;
        &amp;lt;div class="todo-section"&amp;gt;
          &amp;lt;h2&amp;gt;My Todos&amp;lt;/h2&amp;gt;
          &amp;lt;TodoList client:load /&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="stats-section"&amp;gt;
          &amp;lt;TodoStats client:load /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div class="form-section"&amp;gt;
        &amp;lt;TodoForm client:load /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Performance Considerations
&lt;/h2&gt;

&lt;p&gt;This pattern offers several performance benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reduced API calls&lt;/strong&gt; : Multiple components share the same data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smaller bundle sizes&lt;/strong&gt; : No need for a global state management library&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient updates&lt;/strong&gt; : Only affected components re-render&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Controlled refetching&lt;/strong&gt; : Configure when data should be considered stale&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Background updates&lt;/strong&gt; : Users see fresh data without interruption&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Beyond Islands: Towards SPA-like Experiences
&lt;/h2&gt;

&lt;p&gt;This pattern brings us closer to building SPA-like experiences with Astro while maintaining its core performance benefits. By sharing state between islands, we can create applications that feel cohesive and responsive like a traditional SPA, but with the performance advantages of Astro's partial hydration model.&lt;/p&gt;

&lt;p&gt;For many applications, this Astro pattern provides the best of both worlds:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Performance first&lt;/strong&gt; : Ship minimal JavaScript by default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Progressive enhancement&lt;/strong&gt; : Add interactivity only where needed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared state&lt;/strong&gt; : Maintain a cohesive user experience across islands&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified mental model&lt;/strong&gt; : No need to manage server/client boundaries as explicitly as in Next.js&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As this pattern demonstrates, Astro isn't just for static sites with sprinkles of interactivity—it's a viable alternative to frameworks like Next.js for building rich, data-driven applications that prioritize performance without sacrificing user experience.&lt;/p&gt;

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

&lt;p&gt;Sharing state between Astro islands doesn't have to be complicated. By leveraging React Query's powerful caching system and a singleton QueryClient, we can achieve seamless state sharing without sacrificing the performance benefits of Astro's island architecture.&lt;/p&gt;

&lt;p&gt;This pattern is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simple&lt;/strong&gt; : Just a small HOC and a shared client instance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible&lt;/strong&gt; : Works with any React Query features&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient&lt;/strong&gt; : Minimizes API calls and renders&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainable&lt;/strong&gt; : Follows established React patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next time you're building an Astro site with multiple interactive components that need to share data, give this pattern a try. It provides a clean solution to a common problem while maintaining the performance benefits that made you choose Astro in the first place.&lt;/p&gt;

</description>
      <category>astro</category>
      <category>react</category>
      <category>reactquery</category>
      <category>islands</category>
    </item>
    <item>
      <title>A Letter to my Junior Self: Imposter Syndrome</title>
      <dc:creator>jmoreno</dc:creator>
      <pubDate>Sun, 13 Feb 2022 09:55:45 +0000</pubDate>
      <link>https://dev.to/jmoreno/a-letter-to-my-junior-self-imposter-syndrome-1bn4</link>
      <guid>https://dev.to/jmoreno/a-letter-to-my-junior-self-imposter-syndrome-1bn4</guid>
      <description>&lt;p&gt;Imposter syndrome is probably one of the most common issues that new programmers face. The tech industry can seem incredibly daunting from the outside looking in, "make sure you practice leetcode, oh and put together a portfolio, and why are you learning that framework that's old news, all the cool kids have moved on to this new framework."&lt;/p&gt;

&lt;p&gt;Then once you start the job there's a feeling of needing to keep up, to be at the same level as coworkers with much more experience than you, after all if you can't keep up then why did they hire you? Man they're probably even thinking of firing you right now aren't they? &lt;/p&gt;

&lt;p&gt;Of course this is &lt;strong&gt;bullshit&lt;/strong&gt;. The mind likes to exaggerate, in truth you're probably doing fine and a part of you knows this, but the mind is tricky and well it's not exactly wrong. &lt;/p&gt;

&lt;p&gt;The truth is that if you're new you probably &lt;em&gt;can't&lt;/em&gt; keep up with your more experienced coworkers, but the good news is that no one really expects you to in the first place.&lt;/p&gt;

&lt;p&gt;So then how do we deal with imposter syndrome? The following is the process that I followed (I am not a medical professional and if you're truly struggling please reach out to a professional).&lt;/p&gt;

&lt;p&gt;This whole letter is based on the idea that &lt;strong&gt;imposter syndrome is a learned reaction to a given situation&lt;/strong&gt;, it is NOT a moral defect, or flaw in your person, it is simply how we learned to cope with unfamiliar situations. So keep that in mind as you read this letter.&lt;/p&gt;

&lt;p&gt;First step is to simply observe, whenever you're going to be in a situation that has caused your imposter syndrome to flare up before, pay attention to your body, watch how it tenses up, watch how your breath changes, and more importantly &lt;strong&gt;watch the thoughts that are popping up in your head&lt;/strong&gt;. What is the mind presenting you with at this moment? Why? &lt;/p&gt;

&lt;p&gt;This is going to be hard at first, after all you're looking directly at the things that we want to avoid but it is important because we want to be able to see what exactly it is we're afraid of. &lt;/p&gt;

&lt;p&gt;Then, &lt;strong&gt;explore what the fear is really about&lt;/strong&gt;. This might sound silly but it's important to know what exactly it is we're afraid of, is it getting fired? Is it the reputational hit? Is it a deeper fear that maybe you chose the wrong career? Or that you're not smart enough to do this? Let's tackle a few of the common fears. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"I'm scared I might not know how to do this." Why?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Is it because you're &lt;strong&gt;scared you'll lose your job&lt;/strong&gt;? Highly unlikely. If you're just starting out you were most likely hired as a junior. Your company, your coworkers, and frankly most people in tech do not expect that you know everything, we WANT to help you learn, we want to see you succeed. Why do you believe that not knowing something is a basis for being fired? &lt;/p&gt;

&lt;p&gt;Is it because you &lt;strong&gt;don't want to look bad in front of your peers&lt;/strong&gt;? Once again try to explore where you picked up the belief that not knowing how to do something is a bad thing or would make you look bad somehow.&lt;/p&gt;

&lt;p&gt;We want to see you succeed, we want to help, and while most people don't speak openly about it I can promise you that a majority of people have felt this way. &lt;/p&gt;

&lt;p&gt;Keep in mind that developers are fundamentally a curious group of people. We tend to pride ourselves in learning new things, so if someone doesn't know everything but is trying to learn to do things they'll usually be looked on favorably. (And if your coworkers are being elitist assholes about it, fuck them, find the helpers). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are you comparing yourself to some mythical genius programmer who knows everything?&lt;/strong&gt; These types of programmers may exist but in the seven years I've been in the tech industry I've never come across one, even if it looks that way sometimes from the outside. More likely they just have more experience than you and have seen more shit. &lt;em&gt;This is a good thing,&lt;/em&gt; it means you have people to learn from. If you didn't how would anyone ever progress? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it because as a kid you were scolded for not knowing something?&lt;/strong&gt; This one cuts a little deeper but was my personal reason for imposter syndrome, as a kid I was rewarded when I knew things and punished when I didn't. &lt;strong&gt;This is where I internalized the idea that not knowing something was a bad thing.&lt;/strong&gt; This created a very toxic and subconscious behavior in me where I would hide away until I felt confident in doing things, after all I didn't want my parents to be upset with me. Well guess what, we're not kids anymore, no one is going to scold us, and even if someone does, we'll be fine. It might hurt, but we'll be fine. This doesn't mean that our fear is invalid, it just means that it is no longer a useful pattern of behavior.&lt;/p&gt;

&lt;p&gt;Now, once you know what your fear is &lt;em&gt;really&lt;/em&gt; about you have to take probably the hardest step: &lt;strong&gt;Acceptance&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;You have to accept that this fear is there, &lt;strong&gt;having imposter syndrome is simply something that happens to you right now, &lt;em&gt;and that's okay&lt;/em&gt;.&lt;/strong&gt; It shows that you care about your work, it shows that you're conscientious, these are admirable qualities. &lt;/p&gt;

&lt;p&gt;The fear feels unpleasant I know, and we instinctively want to get rid of it. But as you may have noticed pushing it away doesn't work and can even make it worse because now you have the fear and the shame towards having felt that fear. (After all no one else feels it right? What's wrong with us?)&lt;/p&gt;

&lt;p&gt;So instead, &lt;strong&gt;just let it be there&lt;/strong&gt;. It has valid reasons for being there. In my case as a kid I was 100% going to get in trouble for low grades this was a fact of life, so now as an adult my mind was trying to avoid that and it just hadn't realized that we were no longer in that situation. It just wanted to help. So accept it, thank the mind for looking out for you and then teach it how to look out for you in helpful ways. &lt;/p&gt;

&lt;p&gt;This is where we get to retraining our automatic reactions, again imposter syndrome is a learned reaction to a given situation, it is NOT a moral defect, or flaw in your person, it is simply how we learned to cope with unfamiliar situations. &lt;/p&gt;

&lt;p&gt;So how do we retrain ourselves? In my experience the best way is repetition, when imposter syndrome flares up we follow the process: observe our mind, explore the fear, accept that the fear is there, know that the mind is trying to help, and then help it help us. &lt;/p&gt;

&lt;p&gt;If it starts going on about everyone else being smarter than you explain to it that this is simply not true, and even if it is true you're here to learn and grow not to compare yourself with others, so who cares?&lt;/p&gt;

&lt;p&gt;If it starts going on about getting yelled at as a kid for bad grades, comfort it, tell it that it's okay to be scared, and that you know it wants to help but you're no longer there, and if your coworker yells at you &lt;em&gt;they're&lt;/em&gt; the asshole. &lt;/p&gt;

&lt;p&gt;Over time (weeks, months, years) this replaces the automatic reaction of fear and anxiety with an automatic reaction of exploration and acceptance, which means that we'll feel imposter syndrome less and less intensely, and because we're presenting the mind with alternatives it will eventually start to present them back to us and on days where we're feeling low, the mind will remind us that this is okay.&lt;/p&gt;

&lt;p&gt;This is the process I personally followed to get rid of imposter syndrome, fear of public speaking, fear of looking like an idiot in front of my coworkers, and frankly just fear in general. It is hard but man is it worth it. Good luck, you got this.&lt;/p&gt;

&lt;p&gt;For more explorations of this I suggest the following reading list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading List&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Inner Game of Tennis&lt;/li&gt;
&lt;li&gt;Zen Mind Beginner's Mind&lt;/li&gt;
&lt;li&gt;Atomic Habits&lt;/li&gt;
&lt;li&gt;How to Fail at Everything and Still win Big&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>impostersyndrome</category>
      <category>career</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Senior / Intermediate React Interview Questions</title>
      <dc:creator>jmoreno</dc:creator>
      <pubDate>Thu, 10 Feb 2022 16:36:47 +0000</pubDate>
      <link>https://dev.to/jmoreno/react-interview-questions-to-gauge-understanding-3lnn</link>
      <guid>https://dev.to/jmoreno/react-interview-questions-to-gauge-understanding-3lnn</guid>
      <description>&lt;p&gt;Recently I had to come up with a list of interview questions to ask potential senior / intermediate candidates.&lt;/p&gt;

&lt;p&gt;I tried to come up with questions that showed understanding of React issues and use cases rather than surface level memorization. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What problem does React solve?&lt;/strong&gt;&lt;br&gt;
React is a way to develop UIs in a predictable, declarative way. Rather than wiring up changes to the DOM yourself you simply describe what the UI should look like for a given state and React handles the DOM patching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the role of the virtual dom in React, what problems does it attempt to solve?&lt;/strong&gt;&lt;br&gt;
React makes the assumption that DOM manipulation is expensive (kudos if they explain why) so it holds a copy of the DOM in an in memory data structure known as the virtual dom. Differences in the component tree between renders are computed against this virtual representation and React tries to apply the minimal number of changes to the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speak briefly on the component lifecycle&lt;/strong&gt;&lt;br&gt;
At the very least should mention mounting, rendering, unmounting.&lt;br&gt;
Extra points if they can talk about the class based lifecycle and why it is no longer as relevant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the context of React what does one way data flow refer to and what are some of the advantages / disadvantages of this?&lt;/strong&gt;&lt;br&gt;
One way data flow describes how information moves through a react application, information always moves down the tree from parent to child. One of the advantages of this is that it makes application state easier to reason about since we know information will either be local or coming from a parent node.&lt;/p&gt;

&lt;p&gt;One of the disadvantages is that it makes communication between sibling components impossible without an intermediary (parent / state store / context)&lt;/p&gt;

&lt;p&gt;Also makes prop drilling a thing, which isn't necessarily bad but can be messy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elaborate on a few common approaches to sharing state between sibling components&lt;/strong&gt;&lt;br&gt;
Lifting state up, using an outside store, react context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How would you share state between components at different levels of the component tree?&lt;/strong&gt;&lt;br&gt;
Lifting state up, using an outside store, prop drilling is also an option but has the disadvantage of introducing noise into component APIs and potentially causing extra renders which can be an issue in performance critical applications.&lt;/p&gt;

&lt;p&gt;React Context is also an option but setting the value of a context provider will cause the entire subtree to re-render so it is a tool which should be used for values which do not change as often and not for general state management (state usually changes frequently)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a pure component and why would you want to use one?&lt;/strong&gt;&lt;br&gt;
Pure components are components with no side-effects, this allows us to use shouldComponentUpdate or React.memo to compare props and prevent re-renders in performance critical parts of the application.&lt;br&gt;
Pure components are not without cost, in some situations re-rendering the component without comparing props is faster than doing the comparison, this is especially true for smaller components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the context of a react component what is a key?&lt;/strong&gt;&lt;br&gt;
Keys are required when rendering a list of items.&lt;br&gt;
Keys help react keep track of components between renders.&lt;br&gt;
extra points: You can force react to unmount/mount a component by changing the component's key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What problems do refs solve and when would you want to use them?&lt;/strong&gt;&lt;br&gt;
The value of the reference is persisted (stays the same) between component re-renders;&lt;br&gt;
Updating a reference doesn't trigger a component re-render.&lt;br&gt;
Refs provide a way to access DOM nodes or React elements created in the render method.&lt;br&gt;
You would want to use refs for:&lt;br&gt;
    - Managing focus, text selection, or media playback.&lt;br&gt;
    - Triggering imperative animations.&lt;br&gt;
    - Integrating with third-party DOM libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is memoization and why would you want to use it?&lt;/strong&gt;&lt;br&gt;
Memoization is a programming technique that accelerates performance by caching the return values of expensive function calls. A “memoized” function will immediately output a pre-computed value if it’s given inputs that it’s seen before.&lt;br&gt;
You would want to use it to store expensive components / values and make sure they are only computed when necessary. Memoizing trades memory for computation time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Describe what the role of the useEffect hook is, how you would use it, and some common pitfalls.&lt;/strong&gt;&lt;br&gt;
useEffect is used to encapsulate "side-effects" such as data fetching, logging, handling route changes, etc..&lt;br&gt;
useEffect takes in a dependency array and will re-run the body of the hook when those dependencies change.&lt;br&gt;
You can provide a return function that will be called when when the dependencies change before the next body is called.&lt;br&gt;
Gotchas around useEffect usually come from not passing in the required dependencies leading to stale values or from dependencies changing on every render.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does the useEffect hook compare dependencies across renders and what does this mean for complex types?&lt;/strong&gt;&lt;br&gt;
useEffect uses reference / shallow equality for complex data types, this leads to a common "bug" in useEffect where the dependencies are complex types and are redeclared on each render, this can cause the effect to fire more times than the developer intends. &lt;/p&gt;

</description>
      <category>react</category>
      <category>career</category>
      <category>interview</category>
      <category>interviewquestion</category>
    </item>
  </channel>
</rss>
