<?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>Forem: ccsunny</title>
    <description>The latest articles on Forem by ccsunny (@ccsunnydev).</description>
    <link>https://forem.com/ccsunnydev</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%2F264299%2F5d8e2fa7-f549-4e4b-a54e-7cf3fcca273e.png</url>
      <title>Forem: ccsunny</title>
      <link>https://forem.com/ccsunnydev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ccsunnydev"/>
    <language>en</language>
    <item>
      <title>Integrating OpenTelemetry SDK in a React Project</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sat, 02 Aug 2025 06:00:30 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/integrating-opentelemetry-sdk-in-a-react-project-3hed</link>
      <guid>https://forem.com/ccsunnydev/integrating-opentelemetry-sdk-in-a-react-project-3hed</guid>
      <description>&lt;h1&gt;
  
  
  Integrating OpenTelemetry SDK in a React Project
&lt;/h1&gt;

&lt;p&gt;OpenTelemetry is a powerful observability framework that allows developers to collect and export telemetry data from their applications. In this article, we'll walk through the steps to integrate OpenTelemetry into a React project, enabling you to monitor performance and trace requests effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we start, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A React application set up (you can use Create React App).&lt;/li&gt;
&lt;li&gt;Basic understanding of JavaScript and React.&lt;/li&gt;
&lt;li&gt;Node.js and npm installed on your machine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Install OpenTelemetry Packages
&lt;/h2&gt;

&lt;p&gt;First, we need to install the necessary OpenTelemetry packages. Open your terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @opentelemetry/api @opentelemetry/sdk-trace-web @opentelemetry/instrumentation-fetch @opentelemetry/instrumentation-xml-http-request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@opentelemetry/api&lt;/code&gt;: The core API for OpenTelemetry.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@opentelemetry/sdk-trace-web&lt;/code&gt;: The SDK for web applications.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@opentelemetry/instrumentation-fetch&lt;/code&gt;: For tracing fetch requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@opentelemetry/instrumentation-xml-http-request&lt;/code&gt;: For tracing XMLHttpRequests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Set Up OpenTelemetry in Your Application
&lt;/h2&gt;

&lt;p&gt;Next, we need to initialize OpenTelemetry in our React application. Create a new file named &lt;code&gt;otel.js&lt;/code&gt; in the &lt;code&gt;src&lt;/code&gt; directory.&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;// src/otel.js&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;NodeTracerProvider&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;@opentelemetry/node&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;WebTracerProvider&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;@opentelemetry/sdk-trace-web&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;BatchSpanProcessor&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;@opentelemetry/tracing&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;SimpleSpanProcessor&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;@opentelemetry/tracing&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;ConsoleSpanExporter&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;@opentelemetry/tracing&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;registerInstrumentations&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;@opentelemetry/instrumentation&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;FetchInstrumentation&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;@opentelemetry/instrumentation-fetch&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;XMLHttpRequestInstrumentation&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;@opentelemetry/instrumentation-xml-http-request&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initialize the provider&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;provider&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;WebTracerProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Set up span processor and exporter&lt;/span&gt;
&lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addSpanProcessor&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;SimpleSpanProcessor&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;ConsoleSpanExporter&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;

&lt;span class="c1"&gt;// Register instrumentations&lt;/span&gt;
&lt;span class="nf"&gt;registerInstrumentations&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;instrumentations&lt;/span&gt;&lt;span class="p"&gt;:&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;FetchInstrumentation&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;XMLHttpRequestInstrumentation&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="c1"&gt;// Register the provider&lt;/span&gt;
&lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We create a &lt;code&gt;WebTracerProvider&lt;/code&gt; to handle tracing for web applications.&lt;/li&gt;
&lt;li&gt;We use &lt;code&gt;SimpleSpanProcessor&lt;/code&gt; and &lt;code&gt;ConsoleSpanExporter&lt;/code&gt; for demonstration, which logs spans to the console.&lt;/li&gt;
&lt;li&gt;We register instrumentations to automatically trace fetch and XMLHttpRequest calls.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Import OpenTelemetry in Your Application
&lt;/h2&gt;

&lt;p&gt;Now, we need to import our OpenTelemetry setup in the main entry point of your application. Open &lt;code&gt;src/index.js&lt;/code&gt; and add the following line at the top:&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;// src/index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&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="nx"&gt;ReactDOM&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;react-dom/client&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="nx"&gt;App&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;./App&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./otel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Import OpenTelemetry setup&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/React.StrictMode&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;By importing &lt;code&gt;./otel&lt;/code&gt;, we initialize OpenTelemetry when the application starts, allowing it to begin tracing as soon as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Create a Sample Component to Test Tracing
&lt;/h2&gt;

&lt;p&gt;Let’s create a simple component that makes a fetch request. Create a new file called &lt;code&gt;FetchData.js&lt;/code&gt; in the &lt;code&gt;src&lt;/code&gt; directory:&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;// src/FetchData.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&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;react&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;FetchData&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&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="kc"&gt;null&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;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&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;result&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="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nf"&gt;fetchData&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Fetched&lt;/span&gt; &lt;span class="nx"&gt;Data&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;data&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;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&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="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;FetchData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This component fetches data from a placeholder API and displays it.&lt;/li&gt;
&lt;li&gt;The fetch request will be automatically traced by OpenTelemetry due to our previous setup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 5: Use the Component in Your App
&lt;/h2&gt;

&lt;p&gt;Finally, use the &lt;code&gt;FetchData&lt;/code&gt; component in your main &lt;code&gt;App.js&lt;/code&gt; file:&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;// src/App.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&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="nx"&gt;FetchData&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;./FetchData&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;App&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;OpenTelemetry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FetchData&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;FetchData&lt;/code&gt; component is rendered within the main application, allowing us to see the fetched data and the associated traces.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: Run Your Application
&lt;/h2&gt;

&lt;p&gt;Now, run your application with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your browser and navigate to &lt;code&gt;http://localhost:3000&lt;/code&gt;. You should see the fetched data displayed, and you can check your console for any OpenTelemetry traces.&lt;/p&gt;

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

&lt;p&gt;You have successfully integrated OpenTelemetry into your React application! This setup allows you to trace HTTP requests and monitor your application's performance. You can further enhance this integration by exporting traces to a backend observability platform like Jaeger or Zipkin for more advanced analysis.&lt;/p&gt;

&lt;p&gt;Feel free to explore more OpenTelemetry features and customize your setup according to your needs!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>V8 fast-property in Object</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sun, 18 May 2025 13:39:29 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/v8-fast-property-in-object-34m5</link>
      <guid>https://forem.com/ccsunnydev/v8-fast-property-in-object-34m5</guid>
      <description>&lt;p&gt;V8 Object takeaway&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array-indexed properties are stored in a separate elements store.&lt;/li&gt;
&lt;li&gt;Named properties are stored in the properties store.&lt;/li&gt;
&lt;li&gt;Elements and properties can either be arrays or dictionaries.&lt;/li&gt;
&lt;li&gt;Each JavaScript object has a HiddenClass associated that keeps &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Element
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Foo() {
    this[100] = 'test-100'
    this[1] = 'test-1'
    this["B"] = 'bar-B'
    this[50] = 'test-50'
    this[9] = 'test-9'
    this[8] = 'test-8'
    this[3] = 'test-3'
    this[5] = 'test-5'
    this["A"] = 'bar-A'
    this["C"] = 'bar-C'
}
var bar = new Foo()
for(key in bar){
    console.log(`index:${key} value:${bar[key]}`)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Faz22e8xxtu63gkygcc7d.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%2Faz22e8xxtu63gkygcc7d.png" alt="Image description" width="800" height="919"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Property
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Foo2(property_num,element_num) {
    for (let i = 0; i &amp;lt; element_num; i++) {
      this[i] = `element${i}`
    }
    for (let i = 0; i &amp;lt; property_num; i++) {
    let ppt = `property${i}`
    this[ppt] = ppt
}}
var bar2 = new Foo2(20, 10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Ffatiemgfxgjf59hzsmht.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%2Ffatiemgfxgjf59hzsmht.png" alt="Image description" width="800" height="1114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://v8.dev/blog/fast-properties" rel="noopener noreferrer"&gt;https://v8.dev/blog/fast-properties&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>performance</category>
      <category>node</category>
    </item>
    <item>
      <title>Building V8 from source is a huge task for my Mac</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sun, 18 May 2025 11:17:00 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/building-v8-from-source-is-a-huge-task-for-my-mac-1e70</link>
      <guid>https://forem.com/ccsunnydev/building-v8-from-source-is-a-huge-task-for-my-mac-1e70</guid>
      <description>&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%2Fwp8hnik252qjmvydgmoe.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%2Fwp8hnik252qjmvydgmoe.png" alt="Image description" width="800" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Took me an hour finally done...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mac@nico v8 % ./tools/dev/gm.py x64.optdebug
# mkdir -p out/x64.optdebug
# echo &amp;gt; out/x64.optdebug/args.gn &amp;lt;&amp;lt; EOF
is_component_build = true
is_debug = true
symbol_level = 1
target_cpu = "x64"
v8_enable_sandbox = true
v8_enable_backtrace = true
v8_enable_fast_mksnapshot = true
v8_enable_verify_heap = true
v8_optimized_debug = true
EOF
# gn gen out/x64.optdebug
Done. Made 741 targets from 215 files in 2714ms
# autoninja -C out/x64.optdebug d8
ninja: Entering directory `out/x64.optdebug'
[1339/2355] CXX obj/torque_generated_initializers/set-symmetric-difference-tq-csa.o

[1429/2355] CXX obj/torque_generated_initializers/megadom-handler-tq-csa.o



[2355/2355] LINK ./d8
Done! - V8 compilation finished successfully.

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Introducing Baseline: a unified view of stable web features</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Mon, 02 Dec 2024 04:27:28 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/introducing-baseline-a-unified-view-of-stable-web-features-536d</link>
      <guid>https://forem.com/ccsunnydev/introducing-baseline-a-unified-view-of-stable-web-features-536d</guid>
      <description>&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%2F0julaed25n68zus3gz6t.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%2F0julaed25n68zus3gz6t.png" alt="Image description" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Baseline
&lt;/h2&gt;

&lt;p&gt;Baseline is a comprehensive platform that aggregates and curates stable web features from various sources, offering developers a centralized hub to access, compare, and implement the best tools and technologies available. By consolidating information on web standards, browser support, and community recommendations, Baseline serves as an invaluable resource for both novice and experienced developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Baseline?
&lt;/h2&gt;

&lt;p&gt;The web development ecosystem is fragmented, with numerous frameworks, libraries, and APIs emerging regularly. This fragmentation can lead to:&lt;br&gt;
Information Overload: Sifting through vast amounts of data to find reliable and stable features is time-consuming.&lt;br&gt;
Compatibility Issues: Implementing features that lack broad browser support can result in inconsistent user experiences.&lt;br&gt;
Technical Debt: Adopting unstable or deprecated features can lead to increased maintenance efforts and technical debt.&lt;br&gt;
Baseline addresses these challenges by providing:&lt;br&gt;
Centralized Information: A single source for up-to-date information on stable web features.&lt;br&gt;
Reliability: Assurance that the features listed are mature, well-supported, and widely adopted.&lt;br&gt;
Efficiency: Streamlined decision-making processes, allowing developers to focus on building rather than researching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where you can find baseline
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://webstatus.dev/" rel="noopener noreferrer"&gt;https://webstatus.dev/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://web-platform-dx.github.io/web-features/web-features/" rel="noopener noreferrer"&gt;https://web-platform-dx.github.io/web-features/web-features/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why does my flex box become LCP Element only with Text</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sat, 02 Nov 2024 04:52:53 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/why-flex-box-become-lcp-element-only-with-text-3082</link>
      <guid>https://forem.com/ccsunnydev/why-flex-box-become-lcp-element-only-with-text-3082</guid>
      <description>&lt;h3&gt;
  
  
  Why did this div become an LCP (Largest Contentful Paint) element?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="flex gap-1 body-m"&amp;gt;
  &amp;lt;span class="cursor-pointer"&amp;gt;Login&amp;lt;/span&amp;gt;
  or
  &amp;lt;span class="cursor-pointer"&amp;gt;Register Now&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Text Block Calculation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;LCP considers text blocks as a single unit when they're within a block-level container&lt;/li&gt;
&lt;li&gt;This div contains all the text: "Login or Register Now" as one block&lt;/li&gt;
&lt;li&gt;Even though individual span elements are smaller, they're calculated together&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Solutions if you don't want this element as LCP:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use inline element:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span class="flex gap-1"&amp;gt;
  &amp;lt;!-- content --&amp;gt;
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Force other elements to be LCP:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Ensure logo or hero image is larger and loads faster --&amp;gt;
&amp;lt;img 
  src="logo.png" 
  alt="Logo" 
  fetchpriority="high"
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adjust display mode:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;main&amp;gt;
  &amp;lt;h1 class="main-title"&amp;gt;&amp;lt;!-- larger text content --&amp;gt;&amp;lt;/h1&amp;gt;
  &amp;lt;!-- login/register prompt --&amp;gt;
&amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best practices:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Specify your intended LCP element (usually a logo, hero image, or main title)&lt;/li&gt;
&lt;li&gt;Ensure priority loading for that element&lt;/li&gt;
&lt;li&gt;Use inline elements or limit size for secondary text content&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>website</category>
    </item>
    <item>
      <title>How to start Next.js with express</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Mon, 28 Oct 2024 08:55:09 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/how-to-start-nextjs-with-express-5ah5</link>
      <guid>https://forem.com/ccsunnydev/how-to-start-nextjs-with-express-5ah5</guid>
      <description>&lt;h2&gt;
  
  
  Why do we need to start Next.js with express?
&lt;/h2&gt;

&lt;p&gt;When using Next.js with Express, we need to initialize the Next.js application before handling any requests. app.prepare() does several important things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compiles the Next.js application&lt;/li&gt;
&lt;li&gt;Prepares the pages directory
Sets up the development or production environment
Initializes the Next.js server features
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const next = require('next');
const session = require('express-session');
const passport = require('passport');

const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() =&amp;gt; {
    const server = express();

    // Express middleware
    server.use(express.json());
    server.use(session({ /* config */ }));
    server.use(passport.initialize());

    // Custom API routes
    server.use('/api/v1', require('./routes/api'));

    // WebSocket setup
    const httpServer = require('http').createServer(server);
    const io = require('socket.io')(httpServer);

    // Real-time features
    io.on('connection', (socket) =&amp;gt; {
        // Handle socket events
    });

    // Let Next.js handle page routing
    server.all('*', (req, res) =&amp;gt; {
        return handle(req, res);
    });

    httpServer.listen(3000);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Details of next options
&lt;/h2&gt;

&lt;p&gt;Check the details in &lt;a href="https://github.com/vercel/next.js/blob/canary/packages/next/src/server/next.ts" rel="noopener noreferrer"&gt;next/src/server/next.ts&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Shopify ajax api with add cart</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Mon, 07 Oct 2024 03:32:50 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/shopify-ajax-api-with-add-cart-2m2d</link>
      <guid>https://forem.com/ccsunnydev/shopify-ajax-api-with-add-cart-2m2d</guid>
      <description>&lt;p&gt;The Ajax API provides a suite of lightweight REST API endpoints for development of Shopify themes. The Ajax API can only be used by themes that are hosted by Shopify. You can't use the Ajax API on a Shopify custom storefront.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Functionalities:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adding items to the cart&lt;/li&gt;
&lt;li&gt;Updating item quantities in the cart&lt;/li&gt;
&lt;li&gt;Removing items from the cart&lt;/li&gt;
&lt;li&gt;Retrieving the current cart state&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Endpoints:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/cart/add.js: Add items to the cart
/cart/update.js: Update items in the cart
/cart/change.js: Change items in the cart (can be used to add, update, or remove)
/cart.js: Get the current cart state

fetch(window.Shopify.routes.root + 'cart.js')
  .then(response =&amp;gt; response.json())
  .then(cart =&amp;gt; {
    console.log(cart);
  })
  .catch(error =&amp;gt; console.error('Error fetching cart:', error));

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>How to navigate between Shopify app</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sun, 22 Sep 2024 05:24:53 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/how-to-navigate-between-shopify-app-1akl</link>
      <guid>https://forem.com/ccsunnydev/how-to-navigate-between-shopify-app-1akl</guid>
      <description>&lt;p&gt;To redirect to a new page when a button is clicked in a Remix application, you can use the useFetcher hook or a simple button with an onClick handler. Below are two approaches:&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 1: Using useFetcher
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useFetcher } from "@remix-run/react";

function MyButton() {
    const fetcher = useFetcher();

    const handleClick = () =&amp;gt; {
        fetcher.load('/new-url'); // Replace with your target URL
    };

    return (
        &amp;lt;fetcher.Form method="post" onSubmit={handleClick}&amp;gt;
            &amp;lt;button type="button" onClick={handleClick}&amp;gt;
                Go to New Page
            &amp;lt;/button&amp;gt;
        &amp;lt;/fetcher.Form&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Approach 2: Using a Simple Button with useNavigate
&lt;/h2&gt;

&lt;p&gt;If you want a simpler approach without using useFetcher, you can use useNavigate from Remix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useNavigate } from "@remix-run/react";

function MyButton() {
    const navigate = useNavigate();

    const handleClick = () =&amp;gt; {
        navigate('/new-url'); // Replace with your target URL
    };

    return (
        &amp;lt;button onClick={handleClick}&amp;gt;
            Go to New Page
        &amp;lt;/button&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
Approach 1: useFetcher is useful if you want to perform actions that might need to submit data or trigger a loader.&lt;br&gt;
Approach 2: useNavigate is a straightforward way to navigate to a new URL without needing to submit any data.&lt;/p&gt;

</description>
      <category>shopify</category>
      <category>remix</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Chrome extension development: How open popup.html to the right and top of the page</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Tue, 10 Sep 2024 18:11:41 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/chrome-extension-development-how-open-popuphtml-to-the-right-and-top-of-the-page-4dbc</link>
      <guid>https://forem.com/ccsunnydev/chrome-extension-development-how-open-popuphtml-to-the-right-and-top-of-the-page-4dbc</guid>
      <description>&lt;p&gt;Buy default the popup opened below the extension icon, we can change the position by create a new window&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chrome.action.onClicked.addListener(async (tab) =&amp;gt; {
    openPopup(tab)
});

const openPopup = async (tab) =&amp;gt; {
    const currentWindow = await chrome.windows.getCurrent();
    let window = await chrome.windows.create({
        url: './popup.html',
        type: 'popup',
        width: 320,
        height: 578,
        left: currentWindow.left + currentWindow.width - 320,
        top: 100
    });
    chrome.windows.update(window.id, { focused: true });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>restapi</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to add section link to Squarespace</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sun, 25 Aug 2024 09:54:31 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/how-to-add-section-link-to-squarespace-ojh</link>
      <guid>https://forem.com/ccsunnydev/how-to-add-section-link-to-squarespace-ojh</guid>
      <description>&lt;p&gt;To link to a specific section in Squarespace, you can follow these steps:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  1 Identify the Section ID:
&lt;/h3&gt;

&lt;p&gt;Each section in Squarespace has a unique ID. To find it, you can inspect the page using your browser's developer tools (right-click on the section and select "Inspect").&lt;br&gt;
Look for a section with a class like #section-id in the HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  2 Create the Link:
&lt;/h3&gt;

&lt;p&gt;Use the following format to create your link:&lt;br&gt;
bash&lt;br&gt;
Copy&lt;br&gt;
&lt;a href="https://yourwebsite.com#section-id" rel="noopener noreferrer"&gt;https://yourwebsite.com#section-id&lt;/a&gt;&lt;br&gt;
Replace yourwebsite.com with your actual domain and section-id with the ID you found.&lt;/p&gt;

&lt;h3&gt;
  
  
  3 Add the Link:
&lt;/h3&gt;

&lt;p&gt;You can add this link to buttons, navigation menus, or text links in your Squarespace site.&lt;/p&gt;

&lt;h3&gt;
  
  
  4 Test the Link:
&lt;/h3&gt;

&lt;p&gt;After saving your changes, click the link to ensure it scrolls to the correct section.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What's Next.js server actions</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Sat, 24 Aug 2024 13:24:00 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/whats-nextjs-server-actions-n2o</link>
      <guid>https://forem.com/ccsunnydev/whats-nextjs-server-actions-n2o</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwtn0r14oeh2ql06haryn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwtn0r14oeh2ql06haryn.png" alt="Image description" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's server actions
&lt;/h2&gt;

&lt;p&gt;Server action is async functions that runs on server&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;async function&lt;/li&gt;
&lt;li&gt;runs on server&lt;/li&gt;
&lt;li&gt;can called in server component or client component&lt;/li&gt;
&lt;li&gt;can called in form or in useEffect
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function HomePage() {
  // Server Action
  async function updateItemAction() {
    'use server'
    // Mutate data
  }

  return &amp;lt;form action={updateItemAction}&amp;gt;{/* ... */}&amp;lt;/form&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thinking on server action
&lt;/h2&gt;

&lt;p&gt;since server action run on server, so it's provide a endpoint(POST) for other application to, but there is some issues we need to think&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how can we write API documentation for this endpoints?
since we need to learn new concept like server actions, we need to think what's the point of this, personally I don's thinks this is a good way for browser to communicate with server but easy for react projects&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>SEO management in Next.js 14</title>
      <dc:creator>ccsunny</dc:creator>
      <pubDate>Wed, 14 Aug 2024 10:43:33 +0000</pubDate>
      <link>https://forem.com/ccsunnydev/seo-management-in-nextjs-14-1li3</link>
      <guid>https://forem.com/ccsunnydev/seo-management-in-nextjs-14-1li3</guid>
      <description>&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjdqgm451nnekyhyv7xe.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjdqgm451nnekyhyv7xe.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1 What Is SEO – Search Engine Optimization?
&lt;/h2&gt;

&lt;p&gt;SEO stands for “search engine optimization.” In simple terms, SEO means the process of improving your website to increase its visibility in Google, Microsoft Bing, and other search engines whenever people search for:&lt;br&gt;
Products you sell.&lt;br&gt;
Services you provide.&lt;br&gt;
Information on topics in which you have deep expertise and/or experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next SEO and Next.js
&lt;/h2&gt;

&lt;p&gt;Next.js has static site generation (SSG) support, which delivers better SEO capability than client-side rendering. It also has an in-built head component to manage SEO meta information like title, description, canonical, and Open Graph tags.&lt;/p&gt;

&lt;p&gt;We can use a package called next-seo. Next SEO makes managing SEO easier in your Next.js projects.&lt;/p&gt;

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

pnpm add next-seo


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Adding Next SEO to a page
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

//home.js

import { NextSeo } from 'next-seo';

const Home = () =&amp;gt; (
    &amp;lt;&amp;gt;
        &amp;lt;NextSeo
            title="Home Page Title"
            description="Home page description of the page"
        /&amp;gt;
        &amp;lt;p&amp;gt;Simple Usage&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
);

export default Home;


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

&lt;/div&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1nxbe6wx7wg5hxzs10iq.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1nxbe6wx7wg5hxzs10iq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Default SEO
&lt;/h2&gt;

&lt;p&gt;To add default properties to all of our pages, we can use the DefaultSeo component, instead of manually adding the properties individually to each page. We can also override any property on a page, if needed.&lt;/p&gt;

&lt;p&gt;Add the DefaultSeo component to _app.js and add the following code:&lt;/p&gt;

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

//_app.js

import '../styles/globals.css'
import {DefaultSeo} from 'next-seo';

function MyApp({Component, pageProps}) {
    return (
        &amp;lt;&amp;gt;
            &amp;lt;DefaultSeo
                title="Next SEO Example"
                description="Next SEO is a plug in that makes managing your SEO easier in Next.js projects."
                openGraph={{
                    type: 'website',
                    locale: 'en_IE',
                    url: 'https://www.url.ie/',
                    siteName: 'SiteName',
                }}
                twitter={{
                    handle: '@handle',
                    site: '@site',
                    cardType: 'summary_large_image',
                }}
            /&amp;gt;
            &amp;lt;Component {...pageProps} /&amp;gt;
        &amp;lt;/&amp;gt;
    )
}

export default MyApp


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

&lt;/div&gt;

&lt;p&gt;Now we add SEO properties to all page cause we add it on _app.js&lt;/p&gt;

&lt;h2&gt;
  
  
  How to override default SEO properties?
&lt;/h2&gt;

&lt;p&gt;As we add SEO to _app.js works on all page, but we may need some custom logic for different pages like title and meta, We can accomplish this goal by using NextSeo in pages&lt;/p&gt;

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

//blog.js

import {NextSeo} from 'next-seo';

const Blog = () =&amp;gt; (
    &amp;lt;&amp;gt;
        &amp;lt;NextSeo
            title="Manage SEO in NextJS with Next SEO"
            description="Next SEO packages simplifies the SEO management in Next Apps with less configurations"
            canonical="www.example.com/next-seo-blog"
            openGraph={{
                type: 'article',
                article: {
                    publishedTime: '2022-06-21T23:04:13Z',
                    modifiedTime: '2022-01-21T18:04:43Z',
                    authors: [
                        'https://www.example.com/authors/@firstnameA-lastnameA',
                        'https://www.example.com/authors/@firstnameB-lastnameB',
                    ],
                    tags: ['Tag A', 'Tag B', 'Tag C'],
                },
                url: 'www.example.com/next-seo-blog',
                images: {
                    url: 'https://www.test.ie/images/cover.jpg',
                    width: 850,
                    height: 650,
                    alt: 'Photo of text',
                },
                site_name: 'Next Blog'
            }}
        /&amp;gt;
        &amp;lt;p&amp;gt;Manage SEO in NextJS with Next SEO - Blog&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
);

export default Blog;


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

&lt;/div&gt;



&lt;p&gt;Here, we have overridden the title, description, and other properties. You can also see a few new properties specifically related to our blog posts:&lt;/p&gt;

&lt;p&gt;publishedTime: Blog published date&lt;br&gt;
modifiedTime: Blog updated date&lt;br&gt;
tags: Tags associated with the blog post&lt;br&gt;
authors : Author of the blog&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>nextjs</category>
      <category>react</category>
      <category>seo</category>
    </item>
  </channel>
</rss>
