<?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: Muhammad Tanveer</title>
    <description>The latest articles on DEV Community by Muhammad Tanveer (@tanveer_cs).</description>
    <link>https://dev.to/tanveer_cs</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F824278%2F55f8b692-cfee-4896-b335-302e47dde040.jpg</url>
      <title>DEV Community: Muhammad Tanveer</title>
      <link>https://dev.to/tanveer_cs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanveer_cs"/>
    <language>en</language>
    <item>
      <title>Halftone type in WebGL, one draw call per headline</title>
      <dc:creator>Muhammad Tanveer</dc:creator>
      <pubDate>Tue, 27 Oct 2026 09:34:54 +0000</pubDate>
      <link>https://dev.to/tanveer_cs/halftone-type-in-webgl-one-draw-call-per-headline-1gjl</link>
      <guid>https://dev.to/tanveer_cs/halftone-type-in-webgl-one-draw-call-per-headline-1gjl</guid>
      <description>&lt;p&gt;Every large title on this site is drawn as halftone dots. They fly in and assemble after the preloader, push away from the cursor and scatter as you scroll. It looks like an image effect, but the text is real: you can select it, search it, and a screen reader reads it like any other heading. This note covers how that works and what it costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the text, paint over it
&lt;/h2&gt;

&lt;p&gt;The component, &lt;code&gt;DotText&lt;/code&gt;, renders the heading as normal HTML and lays a canvas over it. Once the WebGL scene is ready the element gets an &lt;code&gt;is-live&lt;/code&gt; class, which makes the glyphs transparent while keeping them in the DOM. If WebGL is missing, the context is lost or the page runs in forced-colours mode, the canvas is hidden and an SVG filter draws a static halftone instead. Without JavaScript you get that static version too.&lt;/p&gt;

&lt;p&gt;That split decides most of the rest: layout, wrapping and font loading all belong to CSS, and the canvas only has to copy what the browser already laid out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sampling the glyphs the browser drew
&lt;/h2&gt;

&lt;p&gt;Rendering the string again with &lt;code&gt;fillText&lt;/code&gt; would wrap and kern differently from the DOM. So the sampler walks the element’s text nodes and uses a &lt;code&gt;Range&lt;/code&gt; to read each character’s client rect. Each glyph is drawn on an offscreen 2D canvas at exactly that position, with a horizontal scale that matches the DOM advance in case the canvas picks a slightly different width.&lt;/p&gt;

&lt;p&gt;The display face is a variable font set to a condensed width, and canvas fonts don’t take &lt;code&gt;font-variation-settings&lt;/code&gt;. The closest you get is &lt;code&gt;ctx.fontStretch&lt;/code&gt;, so the computed &lt;code&gt;font-stretch&lt;/code&gt; percentage is mapped to the nearest keyword (&lt;code&gt;extra-condensed&lt;/code&gt; for this face).&lt;/p&gt;

&lt;h2&gt;
  
  
  From coverage to dot sizes
&lt;/h2&gt;

&lt;p&gt;The alpha channel of that canvas is the ink coverage. Two box-blur passes per axis approximate a gaussian, so coverage falls off smoothly at the edge of each stroke. A grid is then laid over the result, and each cell becomes one dot whose radius follows the blurred coverage under it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pitch&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;0.08&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;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.35&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="c1"&gt;// too small to see; skip the point entirely&lt;/span&gt;
&lt;span class="nx"&gt;home&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;rs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dots are full inside a stroke and shrink towards its edge, the same screen the SVG fallback produces, so the two versions match. The grid pitch is 6px on desktop and 4px below 720px, where type is smaller and needs a finer screen to stay readable.&lt;/p&gt;

&lt;h2&gt;
  
  
  All the motion lives in the vertex shader
&lt;/h2&gt;

&lt;p&gt;Each dot gets its home position, radius and four random numbers as attributes, uploaded once. Everything that moves is a uniform: intro progress, scroll scatter, time and the cursor position. The vertex shader works out each dot’s position from those, so a frame is a handful of &lt;code&gt;uniform*&lt;/code&gt; calls and one &lt;code&gt;drawArrays(gl.POINTS)&lt;/code&gt;, whether the title has 2,000 dots or 20,000.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight glsl"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Intro: each dot flies in from its own offset with its own delay&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uProgress&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="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;aRand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;e&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="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;vec2&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uOrigin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;aHome&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;aRand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xy&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;uSpread&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;aRand&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Cursor repulsion&lt;/span&gt;
&lt;span class="kt"&gt;vec2&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;uMouse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;smoothstep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uRadius&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;uMouseStrength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mo"&gt;001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;uPush&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fragment shader draws an anti-aliased disc from &lt;code&gt;gl_PointCoord&lt;/code&gt; and blends towards the accent colour by how hard the cursor is pushing that dot. Colour is read from the element’s computed &lt;code&gt;color&lt;/code&gt;, so theme switches and hover transitions carry over without extra code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building lazily
&lt;/h2&gt;

&lt;p&gt;Sampling is the expensive part: reading pixels back and blurring them is main-thread work. The first version built every title on load, including the footer, and it showed up as long tasks. Now an &lt;code&gt;IntersectionObserver&lt;/code&gt; with a half-viewport margin decides when a title is near enough to sample, and the ticker skips titles that are off-screen or in a hidden tab. A &lt;code&gt;ResizeObserver&lt;/code&gt; and &lt;code&gt;document.fonts.ready&lt;/code&gt; mark the scene dirty, and it rebuilds on the next frame only if it is near the viewport.&lt;/p&gt;

&lt;p&gt;Under &lt;code&gt;prefers-reduced-motion&lt;/code&gt; the dots are drawn once, at rest, and repainted only when the colour changes. No ticker runs at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would keep
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Leave the text in the DOM. The effect is decoration on top of a heading, and it never replaces one.&lt;/li&gt;
&lt;li&gt;Sample what the browser rendered instead of re-implementing text layout.&lt;/li&gt;
&lt;li&gt;Put the per-frame work in a shader and keep the CPU side to uniforms.&lt;/li&gt;
&lt;li&gt;Do the costly setup only when the element is about to be seen.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://muhammad-tanveer-dev.vercel.app/notes/halftone-type-in-webgl" rel="noopener noreferrer"&gt;my site&lt;/a&gt;. I'm Muhammad Tanveer, a full-stack developer in Faisalabad, Pakistan: &lt;a href="https://muhammad-tanveer-dev.vercel.app" rel="noopener noreferrer"&gt;muhammad-tanveer-dev.vercel.app&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webgl</category>
      <category>typography</category>
      <category>performance</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A shared-element page transition in the Next.js App Router</title>
      <dc:creator>Muhammad Tanveer</dc:creator>
      <pubDate>Tue, 27 Oct 2026 09:34:27 +0000</pubDate>
      <link>https://dev.to/tanveer_cs/a-shared-element-page-transition-in-the-nextjs-app-router-2hbi</link>
      <guid>https://dev.to/tanveer_cs/a-shared-element-page-transition-in-the-nextjs-app-router-2hbi</guid>
      <description>&lt;p&gt;When you open a project from the work index on this site, its cover grows from the list to fill the screen, the project name rises in, and the frame lifts away to show the case study. It works across routes in the Next.js App Router, in every browser, without the View Transitions API.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pieces
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;TransitionLink&lt;/code&gt;: a normal &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; that intercepts plain left clicks and asks for an exit before calling &lt;code&gt;router.push&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PageTransitionOverlay&lt;/code&gt;: lives in the root layout, so it survives navigation. It owns the overlay elements and all the timelines.&lt;/li&gt;
&lt;li&gt;A small module, &lt;code&gt;lib/transition.ts&lt;/code&gt;, that connects the two with a registered function instead of React context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The overlay registers its exit function on mount, and the link calls it. Context would have meant a client provider around the whole tree just to pass one callback around.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;_playExit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExitFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setExitFn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExitFn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;_playExit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;triggerExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cb&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="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;MorphFrom&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;_playExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;from&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 default just navigates, so if the overlay isn’t mounted, links still work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Respect the browser first
&lt;/h2&gt;

&lt;p&gt;Before anything animates, the link lets the browser handle Cmd/Ctrl/Shift/Alt clicks and middle clicks, so opening a case study in a new tab works as usual. With reduced motion turned on, the exit function calls straight through to navigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring the shared element
&lt;/h2&gt;

&lt;p&gt;The morph source is the image’s clipping frame, not the image itself, because covers are cropped with &lt;code&gt;object-fit&lt;/code&gt; and their own box can be larger than what you see. If the frame is tiny or off-screen, there’s nothing sensible to grow from, so the link falls back to the plain ink panel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&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;onScreen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentSrc&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;onScreen&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  No blank frame
&lt;/h2&gt;

&lt;p&gt;The overlay image is given the same URL the page is already showing (&lt;code&gt;currentSrc&lt;/code&gt;, so the same &lt;code&gt;next/image&lt;/code&gt; rendition), which makes it a cache hit. It still waits for &lt;code&gt;img.decode()&lt;/code&gt; before the first frame, otherwise there is a single empty frame at the start of the grow that you can see on slower machines.&lt;/p&gt;

&lt;p&gt;Thumbnails are small, though, and a 640px image stretched to full screen looks soft. While the frame grows, a full-width rendition is requested by rewriting the &lt;code&gt;w=&lt;/code&gt; parameter of the optimised image URL. It is swapped in only if it decodes while the overlay is still covering the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grow, navigate, lift
&lt;/h2&gt;

&lt;p&gt;The grow is a GSAP timeline on &lt;code&gt;left/top/width/height&lt;/code&gt; and the corner radius, with &lt;code&gt;expo.inOut&lt;/code&gt;. When it completes it calls &lt;code&gt;router.push&lt;/code&gt;. At the end the frame switches from measured pixels to &lt;code&gt;100%&lt;/code&gt;, so a resize while the next route loads doesn’t leave a gap.&lt;/p&gt;

&lt;p&gt;The overlay watches &lt;code&gt;usePathname()&lt;/code&gt;. When the path changes it scrolls to the top, waits one animation frame so the new page can register its ScrollTriggers, refreshes them, and then reveals: the label leaves first, then the frame slides up while the picture inside it moves down. Because the image lags behind its frame, the exit reads as a curtain rather than a card sliding away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Never trap the user
&lt;/h2&gt;

&lt;p&gt;Navigation can stall on a slow network or fail outright. A five-second timeout reveals the page regardless, so nobody is left staring at a full-screen image. The overlay is &lt;code&gt;aria-hidden&lt;/code&gt; and focus never moves into it; to assistive technology this is an ordinary link to an ordinary page.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://muhammad-tanveer-dev.vercel.app/notes/shared-element-page-transition-nextjs" rel="noopener noreferrer"&gt;my site&lt;/a&gt;. I'm Muhammad Tanveer, a full-stack developer in Faisalabad, Pakistan: &lt;a href="https://muhammad-tanveer-dev.vercel.app" rel="noopener noreferrer"&gt;muhammad-tanveer-dev.vercel.app&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>gsap</category>
      <category>animation</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Cutting Total Blocking Time from 200–500ms to 60–80ms</title>
      <dc:creator>Muhammad Tanveer</dc:creator>
      <pubDate>Tue, 27 Oct 2026 09:34:01 +0000</pubDate>
      <link>https://dev.to/tanveer_cs/cutting-total-blocking-time-from-200-500ms-to-60-80ms-oag</link>
      <guid>https://dev.to/tanveer_cs/cutting-total-blocking-time-from-200-500ms-to-60-80ms-oag</guid>
      <description>&lt;p&gt;This site has a Three.js portrait in the hero and WebGL halftone type on every page title. In local Lighthouse runs (desktop profile) Total Blocking Time sat between 200 and 500ms and the layout shifted by 0.15–0.25 on first load. After the changes below, TBT is around 60–80ms, CLS is close to zero and LCP is 0.9–1.4s. None of the effects were removed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find where the time goes
&lt;/h2&gt;

&lt;p&gt;TBT adds up the part of every main-thread task over 50ms between first paint and interactive. Here, that time came from setup work: initialising Three.js, sampling every halftone title on the page (including ones a full scroll away), and canvases sized at the device’s full pixel ratio.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Ship Three.js only to the browser, after hydration
&lt;/h2&gt;

&lt;p&gt;The portrait is imported with &lt;code&gt;next/dynamic&lt;/code&gt; and &lt;code&gt;ssr: false&lt;/code&gt;. Three.js is no longer in the main bundle and its setup runs after hydration rather than during it. The hero keeps its space with CSS, so nothing moves when the canvas arrives, and if WebGL fails it swaps in a plain image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Three.js only ships to the browser, after hydration.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PortraitField&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./PortraitField&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="na"&gt;ssr&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Do expensive setup only near the viewport
&lt;/h2&gt;

&lt;p&gt;Each halftone title reads its glyphs back from a canvas and blurs them, which takes real main-thread time. Every title used to do this on load. Now an &lt;code&gt;IntersectionObserver&lt;/code&gt; with a &lt;code&gt;50%&lt;/code&gt; root margin gates both the build and the render loop. Titles far down the page, like the footer wordmark, wait until you scroll towards them, and nothing renders while it is off-screen or the tab is hidden.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;io&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;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;entry&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="nx"&gt;near&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&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;near&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;dirty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;rebuild&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="na"&gt;rootMargin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;50% 0px&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Cap the pixel ratio
&lt;/h2&gt;

&lt;p&gt;A 3x phone screen means nine times the fragments of a 1x screen, and halftone dots don’t get noticeably sharper past 2x. The canvases cap the device pixel ratio at 2, and at 1.5 on devices with four cores or fewer, or with Data Saver turned on.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Fix the layout shift at the source
&lt;/h2&gt;

&lt;p&gt;Most of the CLS came from the web fonts. The condensed display face is much narrower than its fallback, so headlines rewrapped when it loaded. On a first visit, while the preloader is up anyway, a small inline script now hides the page until the three fonts have loaded, capped at two seconds. Repeat visits and reduced-motion users skip the wait entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Put budgets in CI
&lt;/h2&gt;

&lt;p&gt;Numbers drift without a check. Every pull request runs Lighthouse CI with budgets: LCP under 2s and CLS under 0.05 fail the build, accessibility and SEO under 0.95 fail it too, and TBT over 200ms raises a warning (lab runs have no INP, so TBT stands in for it).&lt;/p&gt;

&lt;h2&gt;
  
  
  What mattered most
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Most of the cost was work done too early, not work that was too slow. Deferring it was enough.&lt;/li&gt;
&lt;li&gt;Gate WebGL on visibility: build near the viewport and stop rendering off-screen.&lt;/li&gt;
&lt;li&gt;Fix CLS where it starts (fonts), instead of reserving space around every heading.&lt;/li&gt;
&lt;li&gt;Measure with budgets in CI, so a regression shows up on the pull request that caused it.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://muhammad-tanveer-dev.vercel.app/notes/cutting-total-blocking-time-webgl-portfolio" rel="noopener noreferrer"&gt;my site&lt;/a&gt;. I'm Muhammad Tanveer, a full-stack developer in Faisalabad, Pakistan: &lt;a href="https://muhammad-tanveer-dev.vercel.app" rel="noopener noreferrer"&gt;muhammad-tanveer-dev.vercel.app&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>performance</category>
      <category>nextjs</category>
      <category>webperf</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering the Core Concepts of Angular</title>
      <dc:creator>Muhammad Tanveer</dc:creator>
      <pubDate>Tue, 02 Apr 2024 12:47:03 +0000</pubDate>
      <link>https://dev.to/tanveer_cs/mastering-the-core-concepts-of-angular-575l</link>
      <guid>https://dev.to/tanveer_cs/mastering-the-core-concepts-of-angular-575l</guid>
      <description>&lt;p&gt;Angular is a comprehensive framework for building dynamic and interactive web applications. To harness its full potential, developers must grasp its core concepts, which form the backbone of Angular development. In this article, we'll explore these fundamental concepts in detail, accompanied by illustrative examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Components
&lt;/h2&gt;

&lt;p&gt;Components are the building blocks of Angular applications. They encapsulate the logic, data, and UI elements of a specific part of the application. Here's an example of a simple Angular component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&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;@angular/core&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="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-greeting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;h1&amp;gt;Hello, {{ name }}!&amp;lt;/h1&amp;gt;&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;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GreetingComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;GreetingComponent&lt;/code&gt; is a basic Angular component that displays a greeting message with the name "John." The &lt;code&gt;@Component&lt;/code&gt; decorator defines the component's metadata, including its selector and template.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Directives
&lt;/h2&gt;

&lt;p&gt;Angular directives are markers on a DOM element that tell Angular to do something with that element. There are two types of directives: structural directives and attribute directives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structural Directives:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"isLoggedin"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Welcome, User!&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;*ngIf&lt;/code&gt; is a structural directive that conditionally renders the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element based on the value of the &lt;code&gt;isLoggedin&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attribute Directives:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;[ngModel]=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;ngModel&lt;/code&gt; is an attribute directive that establishes two-way data binding between the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; element and the &lt;code&gt;username&lt;/code&gt; property in the component class.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Services
&lt;/h2&gt;

&lt;p&gt;Services are reusable components in Angular that encapsulate common functionality and data manipulation tasks. They are typically injected into Angular components or other services to provide specific functionalities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&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;@angular/core&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="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&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="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DataService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;getData&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Item 3&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;DataService&lt;/code&gt; is a service that provides a method &lt;code&gt;getData()&lt;/code&gt; to fetch an array of items. The &lt;code&gt;@Injectable&lt;/code&gt; decorator marks the class as a service, and &lt;code&gt;providedIn: 'root'&lt;/code&gt; registers it with the root injector.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Dependency Injection (DI)
&lt;/h2&gt;

&lt;p&gt;Angular uses dependency injection to provide components and services with the dependencies they need. Dependencies are declared in the constructor of a component or service, and Angular's injector automatically resolves and injects them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&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;@angular/core&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;DataService&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;./data.service&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="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-item-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;ul&amp;gt;
      &amp;lt;li *ngFor="let item of items"&amp;gt;{{ item }}&amp;lt;/li&amp;gt;
    &amp;lt;/ul&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ItemListComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;dataService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DataService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;ngOnInit&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;items&lt;/span&gt; &lt;span class="o"&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;dataService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getData&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;p&gt;In this example, &lt;code&gt;ItemListComponent&lt;/code&gt; depends on &lt;code&gt;DataService&lt;/code&gt; to fetch the list of items. The service is injected into the component's constructor, and its &lt;code&gt;getData()&lt;/code&gt; method is called in the &lt;code&gt;ngOnInit()&lt;/code&gt; lifecycle hook.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Modules
&lt;/h2&gt;

&lt;p&gt;Modules in Angular are used to organize the application into cohesive blocks of functionality. They group related components, directives, pipes, and services together. Angular applications typically have a root module (&lt;code&gt;AppModule&lt;/code&gt;) and may have additional feature modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NgModule&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;@angular/core&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;BrowserModule&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;@angular/platform-browser&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;AppComponent&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;./app.component&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;GreetingComponent&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;./greeting.component&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;ItemListComponent&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;./item-list.component&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;DataService&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;./data.service&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="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;GreetingComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ItemListComponent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;BrowserModule&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;DataService&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;AppModule&lt;/code&gt; is the root module of the Angular application. It declares the &lt;code&gt;AppComponent&lt;/code&gt;, &lt;code&gt;GreetingComponent&lt;/code&gt;, and &lt;code&gt;ItemListComponent&lt;/code&gt;, imports the &lt;code&gt;BrowserModule&lt;/code&gt;, provides the &lt;code&gt;DataService&lt;/code&gt;, and specifies the bootstrap component (&lt;code&gt;AppComponent&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Templates and Data Binding
&lt;/h2&gt;

&lt;p&gt;Templates in Angular combine HTML with Angular markup and directives to define the UI of a component. Data binding allows for the synchronization of data between the component class and its template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{{ title }}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"onClick()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this template snippet, &lt;code&gt;{{ title }}&lt;/code&gt; uses interpolation to display the value of the &lt;code&gt;title&lt;/code&gt; property from the component class, while &lt;code&gt;(click)="onClick()"&lt;/code&gt; sets up an event binding that calls the &lt;code&gt;onClick()&lt;/code&gt; method when the button is clicked.&lt;/p&gt;

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

&lt;p&gt;Mastering the core concepts of Angular is essential for developing robust and scalable web applications. Components, directives, services, dependency injection, modules, templates, and data binding are the building blocks that empower developers to create dynamic and interactive user experiences. By understanding these concepts and leveraging them effectively, developers can unleash the full potential of Angular for modern web development.&lt;/p&gt;




&lt;p&gt;This article provides an in-depth exploration of Angular's core concepts, complete with illustrative examples to aid in understanding and application. By familiarizing yourself with these fundamental concepts, you'll be well-equipped to embark on your journey as an Angular developer.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>what is the meaning of static in typescript classes?</title>
      <dc:creator>Muhammad Tanveer</dc:creator>
      <pubDate>Mon, 01 Jan 2024 09:40:19 +0000</pubDate>
      <link>https://dev.to/tanveer_cs/what-is-the-meaning-of-static-in-typescript-classes-14fb</link>
      <guid>https://dev.to/tanveer_cs/what-is-the-meaning-of-static-in-typescript-classes-14fb</guid>
      <description>&lt;p&gt;In TypeScript, the &lt;code&gt;static&lt;/code&gt; keyword is used to define properties or methods that belong to the class itself rather than to instances of the class. Here are the key aspects of &lt;code&gt;static&lt;/code&gt; in TypeScript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Static Properties:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;When a property is declared as &lt;code&gt;static&lt;/code&gt; in a class, it means that the property is associated with the class itself, not with instances of the class.&lt;/li&gt;
&lt;li&gt;Static properties are accessed using the class name, not an instance of the class.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;myStaticProperty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MyClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myStaticProperty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Accessing static property&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Similar to static properties, static methods are associated with the class rather than instances.&lt;/li&gt;
&lt;li&gt;They are called on the class itself, not on an instance of the class.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MathOperations&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MathOperations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Calling static method&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Singleton Pattern:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;In TypeScript, the &lt;code&gt;static&lt;/code&gt; keyword is often used in conjunction with the Singleton pattern.&lt;/li&gt;
&lt;li&gt;By declaring a &lt;code&gt;static&lt;/code&gt; property that holds a single instance of the class, you ensure that only one instance exists throughout the application.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singleton&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;constructor&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;static&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Singleton&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&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;instance&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;Singleton&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;singletonInstance1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&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;singletonInstance2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;singletonInstance1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;singletonInstance2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No Access to Instance Members:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Inside a &lt;code&gt;static&lt;/code&gt; method, you cannot directly access instance members (properties or methods) of the class because the method is associated with the class, not a specific instance.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;staticMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="c1"&gt;// Can't access instance property directly&lt;/span&gt;
           &lt;span class="c1"&gt;// console.log(this.instanceProperty); // Error&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;

       &lt;span class="nl"&gt;instanceProperty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, &lt;code&gt;static&lt;/code&gt; in TypeScript is used to define properties and methods that are associated with the class itself, rather than with instances of the class. It is commonly used for utility methods, constants, and for implementing patterns like the Singleton pattern.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
