<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nitesh Soni on Medium]]></title>
        <description><![CDATA[Stories by Nitesh Soni on Medium]]></description>
        <link>https://medium.com/@nids.nitesh?source=rss-65ccc08ee6c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HfR2lezISSO5X_g-TnsI9g.jpeg</url>
            <title>Stories by Nitesh Soni on Medium</title>
            <link>https://medium.com/@nids.nitesh?source=rss-65ccc08ee6c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:40:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nids.nitesh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Frontend Isn’t Dead. It Just Stopped Being About Centering Divs.]]></title>
            <link>https://medium.com/front-end-weekly/frontend-isnt-dead-it-just-stopped-being-about-centering-divs-d77e024d61df?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d77e024d61df</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Tue, 10 Nov 2026 18:32:57 GMT</pubDate>
            <atom:updated>2026-11-10T18:32:57.081Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Why AI tools, full-stack hype, and low-code builders aren’t killing frontend engineering , they’re finally forcing it to grow up.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubztSxk1zOmKyUAEtzo1Eg.png" /></figure><p>Every six months, tech Twitter (or whatever we’re calling it this week) finds a new obituary to write.</p><p>Not too long ago, backend was supposedly dead because serverless and Supabase would handle everything. Before that, mobile was dead because PWAs were taking over. And lately, the hot take making the rounds on podcasts and LinkedIn carousels is predictable:</p><blockquote><em>“With Claude Artifacts, v0, Bolt, and Devin generating production-ready React components from a single prompt, is frontend development officially dead?”</em></blockquote><p>If your definition of frontend engineering was translating Figma wireframes into JSX and spending three hours debugging flexbox wrapping, then yes: <strong>that job is dead.</strong> Good riddance.</p><p><strong>Frontend engineering as a discipline is more alive, complex, and critical than it has ever been.</strong></p><p>Here is what’s actually happening.</p><h3>1. The “First 80%” Illusion</h3><p>AI code generators are wizardry at the first 80%.</p><p>They give you the buttons, the cards, the mock state, the responsive grid, and the crisp drop shadows. It looks complete, it demos beautifully to executives, and it makes for an incredible 30-second video on X.</p><p>Then you run into the remaining 20% — which, as every experienced engineer knows, consumes 80% of the actual effort:</p><ul><li><strong>What happens when the WebSocket connection drops during an optimistic state update?</strong></li><li><strong>How does the app handle a race condition between a debounced search input and a cached query response?</strong></li><li><strong>Is that fancy animated dropdown keyboard-navigable and accessible to screen readers?</strong></li><li><strong>Why is the bundle size 4.2 MB, and why is the main thread freezing for 300ms on low-end Android devices?</strong></li><li><strong>How do you synchronize an offline SQLite database via Web Workers with a cloud backend?</strong></li></ul><p>AI tools output <em>static representations of dynamic problems</em>. They generate snapshots. But software is not a snapshot; it’s a living, breathing finite-state machine that exists in an hostile environment known as the user’s browser.</p><p>Building the UI is no longer the bottleneck. <strong>Orchestrating state, resilience, and UX edge cases is.</strong></p><h3>2. The Browser Is the New Operating System</h3><p>Ten years ago, the frontend was a thin presentation layer. The backend did the heavy lifting, rendered an HTML page (or shipped JSON), and the browser’s job was mostly to paint pixels and handle form submissions.</p><p>Look at the modern web today:</p><ul><li><strong>Figma</strong> runs a C++ WebAssembly engine and custom WebGL renderer inside a browser tab.</li><li><strong>Linear and Superhuman</strong> run local-first architectures with in-memory sync engines, making web apps feel faster than native desktop applications.</li><li><strong>Canva, Webflow, and Spline</strong> perform 3D rendering, canvas manipulation, and audio/video processing directly on the client.</li><li><strong>AI in the browser</strong> is already executing quantized LLMs (via WebGPU and ONNX Runtime) directly on users’ graphics chips without touching a server.</li></ul><p>When did building applications on top of WebAssembly, WebGPU, Web Workers, IndexedDB, and CRDTs (Conflict-free Replicated Data Types) become “easy” or “trivial”?</p><p>The web platform didn’t shrink. It expanded into a full-fledged distributed operating system.</p><h3>3. “Full-Stack” Didn’t Erase Frontend — It Increased the Stakes</h3><p>The rise of meta-frameworks like Next.js, Remix, and Nuxt blurred the lines between client and server. For a moment, people claimed: <em>“Everyone is just full-stack now. Specialized frontend is unnecessary.”</em></p><p>What actually happened?</p><p>Frontend engineers suddenly needed to understand:</p><ul><li>Server Components (RSC) and streaming HTML architectures</li><li>Edge caching strategies and stale-while-revalidate semantics</li><li>Hydration mismatches and partial hydration primitives (Islands architecture)</li><li>Cold-start latencies and data waterfalls across server/client boundaries</li></ul><p>The surface area of knowledge required to build a top-tier web application didn’t contract; <strong>it doubled</strong>.</p><p>A backend developer can spin up an API endpoint in twenty minutes. But ask that same engineer to architect a seamless, optimistic, accessible real-time collaboration canvas with sub-16ms frame budgets, and the distinction between “writing code that runs” and “engineering an interface” becomes blindingly obvious.</p><h3>4. The Shift: From UI Typist to Interface Architect</h3><p>If you view your value as how fast you can write CSS rules or construct boilerplate CRUD forms, AI is going to replace your day-to-day workflow. And honestly, you should welcome that.</p><p>Nobody entered computer science hoping to spend their career writing their forty-seventh modal dialog or hand-crafting a datepicker regex.</p><p>The role of the frontend developer is shifting from <strong>builder of widgets</strong> to <strong>architect of experiences</strong>:</p><p>Yesterday’s Frontend Tomorrow’s Frontend Writing HTML &amp; CSS from mockups Designing resilient component architectures &amp; design systems Manually wiring up REST endpoints Managing distributed state, caching, &amp; offline synchronization Fixing browser layout quirks Optimizing Core Web Vitals, runtime memory, and frame rates Implementing designs Ensuring systemic accessibility (a11y), internationalization, and usability Writing boilerplate React state Directing AI prompts and auditing generated code for security and scale</p><p>AI doesn’t eliminate the frontend engineer; it gives them an army of junior interns. It allows one engineer to accomplish in an afternoon what used to take a five-person squad three weeks. But someone still has to know <em>what</em> to build, <em>how</em> the pieces fit together, and <em>why</em> a particular architectural decision will break under 100,000 concurrent users.</p><h3>The Verdict</h3><p>Every time abstraction levels rise in software engineering, doomsayers predict the end of the craft:</p><ul><li>Compilers were supposed to kill programming because nobody needed assembly anymore.</li><li>4GL and visual builders were supposed to kill software agencies in the 90s.</li><li>WordPress and Squarespace were supposed to kill web development in the 2010s.</li></ul><p>Yet, there are more software engineers today than ever before. Why? Because when the cost of creating software drops, the <strong>demand for bespoke, high-quality, high-performance software skyrockets.</strong></p><p>Frontend isn’t dead.</p><p>The bar just got raised. The trivia is being automated away, leaving behind the only part that ever truly mattered: <strong>crafting software that humans love to use.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d77e024d61df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/frontend-isnt-dead-it-just-stopped-being-about-centering-divs-d77e024d61df">Frontend Isn’t Dead. It Just Stopped Being About Centering Divs.</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YouTube’s Feed Was Ruining My Focus. So I Engineered My Own UI.]]></title>
            <link>https://medium.com/@nids.nitesh/youtubes-feed-was-ruining-my-focus-so-i-engineered-my-own-ui-2c4b1efec4ed?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4b1efec4ed</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Wed, 29 Jul 2026 02:58:45 GMT</pubDate>
            <atom:updated>2026-07-30T08:16:46.099Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>PinTube is a lightweight, privacy-first Manifest V3 extension that turns YouTube into an intentional learning workspace.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NRM6E6iBUr2l23S_p5yQEA.png" /></figure><h3><strong>🧠 The Problem: The Algorithmic Trap</strong></h3><p>YouTube is an incredible platform for learning, but its interface is engineered for a very different purpose: <strong>maximizing watch time through endless algorithmic recommendations.</strong></p><p>We’ve all been there:</p><ul><li>You open YouTube to search for a specific system design talk or coding tutorial.</li><li>Before you can even type in the search bar, 12 high-dopamine thumbnails compete for your attention.</li><li>When you spot a great 30-minute lecture you want to watch later, you either save it to a bloated <strong>Watch Later</strong> playlist where videos go to be forgotten, keep 50 open tabs, or lose track of it when the feed refreshes.</li></ul><h3><strong>🛠️ Why I Built PinTube</strong></h3><p>I looked for existing Chrome extensions to solve this, but found they were severely limited:</p><ul><li>They only worked on the homepage grid.</li><li>They broke during YouTube’s inline video autoplay previews.</li><li>They lacked watch-page integration and real-time Shorts removal across dynamic left navigation drawers.</li></ul><p>I wanted to make YouTube a <strong>focused, intentional productivity tool again, </strong>something sorely missing in today’s algorithmic web. So I built <strong>PinTube</strong>.</p><h3><strong>✨ Core Features</strong></h3><p>1. <strong>📌 Pin Videos Anywhere</strong>: Hover over any video thumbnail on Home, Search (/results), or Recommendations to pin it.</p><p>2. <strong>📺 Watch Page Pin Button</strong>: Injects a native-styled <strong>📌 Pin / Pinned</strong> pill button right next to the Subscribe button on /watchpages.</p><p>3. <strong>🏠 Homepage Pinned Shelf</strong>: Your pinned videos sit in a clean, collapsible grid shelf at the top of your homepage.</p><p>4. <strong>🎯 Focus Mode</strong>: Toggling Focus Mode suppresses the endless homepage feed, category filter chips, and sidebars. Only your Pinned shelf and the Search Bar remain active.</p><p>5. <strong>🚫 Shorts Remover</strong>: Cleanly eliminates Shorts shelves, recommendation reels, and left drawer menu items across YouTube in real time.</p><p>6. <strong>🎬 Auto Theater Mode</strong>: Automatically switches watch pages into Theater Mode and cleans up endscreen popups upon completion.</p><h3><strong>🔬 Engineering Highlight: 60fps Viewport Position Sync</strong></h3><p>YouTube’s homepage uses `ytd-inline-preview-renderer for hover video previews, creating an isolated stacking context that paints over DOM-injected elements inside thumbnails. Standard `position: fixed` CSS also suffers from scroll drift because YouTube scrolls inside nested containers (ytt-app).</p><p>PinTube solves this by mounting a floating overlay on `document.body` in the root stacking context, combined with a <strong>60fps </strong><strong>requestAnimationFrame (RAF) loop</strong>:</p><pre>function syncOverlayPosition() {<br>  if (!activeCard || !floatingOverlay) return;<br>  const rect = (activeThumb || activeCard).getBoundingClientRect();<br>  floatingOverlay.style.setProperty(&#39;left&#39;, (rect.left + 8) + &#39;px&#39;, &#39;important&#39;);<br>  floatingOverlay.style.setProperty(&#39;top&#39;,  (rect.top  + 8) + &#39;px&#39;, &#39;important&#39;);<br>}</pre><p>This delivers pixel-perfect, non-drifting overlay alignment that remains 100% immune to autoplay iframe previews.</p><h3><strong>🔮 What’s Next: Future Functionality</strong></h3><p>PinTube v1.0 is just the foundation. Future updates will include:</p><p>📂 <strong>Topic-Based Pinned Queues</strong> (grouping pins by subject like <em>System Design</em> or <em>Rust</em>).</p><p>⏱️ <strong>Intentional Session Timers &amp; Focus Presets</strong>.</p><p>📚 <strong>Smart Queue Auto-Archiving</strong> for watched videos.</p><h3><strong>🏪 Store Release &amp; Early Access</strong></h3><h4><strong>📢 Coming Soon to Chrome Web Store!</strong></h4><p>PinTube is currently undergoing review for the official <strong>Google Chrome Web Store</strong>. Once live, you will be able to install it with one click and receive automatic background updates!</p><h4><strong>⚡ Try Early Access via GitHub Releases Today!</strong></h4><p>In the meantime, you can try PinTube right now:</p><p>1. Go to the <a href="https://github.com/nidsnitesh/Pintube/releases"><strong>PinTube GitHub Releases</strong></a> page.</p><p>2. Download pintube-extension.zip .</p><p>3. Unzip the file.</p><p>4. Open Chrome -&gt; chrome://extensions -&gt; enable <strong>Developer mode</strong>-&gt; click <strong>Load unpacked </strong>and select the unzipped folder.</p><h3><strong>⭐️ Open Source &amp; Community</strong></h3><p>PinTube is 100% private with zero tracking. Check out the source code or star the repo:</p><p>👉 <strong>GitHub Repository</strong>: <a href="https://github.com/nidsnitesh/Pintube">https://github.com/nidsnitesh/Pintube</a><br>💼 <strong>Connect on LinkedIn</strong>: <a href="https://www.linkedin.com/in/niteshsonii/">https://www.linkedin.com/in/niteshsonii/</a></p><p><em>Stay tuned for the official Chrome Store release announcement!</em> 📌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4b1efec4ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ending the debate on few anti-patterns in React]]></title>
            <link>https://medium.com/@nids.nitesh/ending-the-debate-on-few-anti-patterns-in-react-8a4118d175b5?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a4118d175b5</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-performance]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 19:27:18 GMT</pubDate>
            <atom:updated>2019-07-02T07:17:02.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Tg9WWwk0uZiycidK9okSdA.jpeg" /></figure><p>Pure render optimized React components can be extremely performant but it requires users to treat their data as immutable for it to work properly. Unfortunately due to nature of Javascript it can be quite challenging sometimes.</p><blockquote>The anti-pattern is creating new arrays, objects, functions or any other new identities during render.</blockquote><h4>Pure render?</h4><p>With React.js pure render I mean components that implement the <em>shouldComponentUpdate </em>method<em> </em>with shallow equality checks. Examples of this are the <a href="https://facebook.github.io/react/docs/react-api.html#react.purecomponent">React.PureComponent</a>, <a href="https://facebook.github.io/react/docs/pure-render-mixin.html">PureRenderMixin</a>, <a href="https://github.com/acdlite/recompose#optimize-rendering-performance">recompose/pure</a> and many others.</p><h4>Why?</h4><p>It is probably the single most significant performance optimization you can do in React. It is also basically what ClojureScript wrappers for React can do by default and is why they can claim to be faster than vanilla React. For it to work immutable data structures must be used for the state because it makes it really cheap to check whether it is necessary to re-render the components. With mutable data deep equality checks are required which can be really expensive. In ClojureScript this is easy because everything is immutable always. In Javascript not so much.</p><p>To be fair React is reasonably fast even without the pure render optimization but especially with Javascript based animations (ex. react-motion) where the components can be rendered hundreds of times in a second or with big components such as editable tables with hundreds cells the optimization can become quite essential. Also mobile devices with slower CPUs will see a bigger benefit from this.</p><h3>The anti-pattern</h3><p>Few months back I wrote table editor which was used to import users from spreadsheets that our customers sent to us. The sheets could easily contain over 500 users. In a fairly top level component I had written something like this:</p><pre>class Table extends PureComponent {<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        {this.props.items.map(i =&gt;<br>          &lt;Cell data={i} options={this.props.options || []} /&gt;<br>         )}<br>       &lt;/div&gt;<br>     );<br>  }<br>}</pre><p>In reality this was much more complicated. The Cell component was even more complicated and the app rendered multiple cells for each user. So there were thousands Cell elements in the app.</p><p>After a hacking a while I loaded 500 users into the app and I tried to edit one cell and the edit operation took over a second on my fairly performant PC to complete! After some quick <em>console.log()</em> debugging I saw that almost my whole app was being re-rendered for the small one cell change. How it can be? I was using Redux, deep freezing my state and living the immutable dream!</p><p>After hours of scratching my head I realized that one of the changes I recently made was the default array value for the options prop:</p><pre>this.props.options <strong>|| []</strong></pre><p>You see the options array was passed deep down in the Cell elements. Normally this would not be an issue. The other Cell elements would not be re-rendered because they can do the cheap shallow equality check and skip the render entirely but in this case the options prop was <em>null</em> and the default array was used. As you should know the array literal is the same as <em>new Array()</em>which creates a new array instance. This completely destroyed every pure render optimization inside the Cell elements. <strong>In Javascript different instances have different identities and thus the shallow equality check always produces false and tells React to re-render the components.</strong></p><p>The fix was easy:</p><pre><strong>const default = [];</strong><br>class Table extends PureComponent {<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        {this.props.items.map(i =&gt;<br>          &lt;Cell data={i} options={this.props.options || <strong>default</strong>} /&gt;<br>         )}<br>       &lt;/div&gt;<br>     );<br>  }<br>}</pre><p>Now the edit operation took only few dozen milliseconds! The <em>defaultProps</em>class property could also have been used.</p><h4>Functions create identities too</h4><p>Functions created in render will also have exactly the same issue. Too often following code is written</p><pre>class App extends PureComponent {<br>  render() {<br>    return &lt;MyInput<br>      onChange={e <strong>=&gt;</strong> this.props.update(e.target.value)} /&gt;;<br>  }<br>}</pre><p>or</p><pre>class App extends PureComponent {<br>  update(e) {<br>    this.props.update(e.target.value);<br>  }<br>  render() {<br>    return &lt;MyInput onChange={this.update<strong>.bind(this)</strong>} /&gt;;<br> }<br>}</pre><p>In both cases a new function is created with a new identity. Just like with the array literal. You need to bind the function early:</p><pre>class App extends PureComponent {<br>  constructor(props) {<br>    super(props);<br>    <strong>this.update = this.update.bind(this);</strong><br>  }<br>  update(e) {<br>    this.props.update(e.target.value);<br>  }<br>  render() {<br>    return &lt;MyInput onChange={<strong>this.update</strong>} /&gt;;<br>  }<br>}</pre><p>This is bit repetitive though. Other options are to use <em>React.createClass()</em>which automatically binds all methods or to use arrow functions with <a href="https://github.com/jeffmo/es-class-fields-and-static-properties">Class Instance Fields</a> proposal with Babel. There’s also this <a href="https://www.npmjs.com/package/autobind-decorator">autobind decorator</a>.</p><p>ESLint rule <a href="https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md"><em>react/jsx-no-bind</em></a> is a great tool for catching this.</p><p>But some people argue that these two reasons are not solid enough to enforce this rule on all projects, especially when the solutions will introduce more codes and decrease readability. In <a href="https://github.com/airbnb/javascript/blob/eslint-config-airbnb-v17.1.0/packages/eslint-config-airbnb/rules/react.js#L93">Airbnb ESLint preset</a>, the team only bans the usage of .bind, but allows arrow function in both props and refs. I did some googling, and was convinced that this rule is not quite necessary. Someone says it’s premature optimization, and you should measure before you optimize. I agree with that. In the following sections, I will illustrate how arrow function would affect the pure component, what solutions we can use, and talk a little bit about React rendering internals.</p><h3>Different Types of React Component</h3><p>The regular way to create a React component is to extend the React.Component class and implement the render method. There is also a built-in React.PureComponent, which implements the life-cycle method shouldComponentUpdate for you. In regular component, this method will always return true, indicating that React should call render whenever the props or states change. PureComponent, on the other hand, does a shallow identity comparison for the props and states to see whether this component should be re-rendered. The following two components behave the same:</p><pre>class PureChild extends React.PureComponent {<br>  render() {<br>    return (<br>      &lt;div&gt;{this.props.message}&lt;/div&gt;<br>    )<br>  }<br>}<br><br>class RegularChild extends React.Component {<br>  shouldComponentUpdate(nextProps, nextStates) {<br>    return this.props.message !== nextProps.message<br>  }<br><br>  render() {<br>    return (<br>      &lt;div&gt;{this.props.message}&lt;/div&gt;<br>    )<br>  }<br>}</pre><p>When their parent component is re-rendering, they will both check the message content in props and decide whether they should render again. The comparison rule is quite simple in pure component, it iterates the props and states object, compare each others’ members with === equality check. In JavaScript, only primitive types and the very same object will pass this test, for example:</p><pre>1 === 1<br>&#39;hello world&#39; === &#39;hello world&#39;<br>[] !== []<br>(() =&gt; {}) !== (() =&gt; {})</pre><p>Clearly, arrow functions will fail the test and cause pure component to re-render every time its parent is re-rendered. On the other side, if you do not use pure component, or do props and states check on your own, enabling the jsx-no-bind rule is plain unnecessary.</p><p>Recently another kind of component has become popular, the stateless functional component (SFC). These components’ render results solely depend on their props, so they are like functions that take inputs and produce steady outputs. But under the hood, they are just regular components, i.e. they do not implement shouldComponentUpdate, and you can not implement by yourself either.</p><pre>const StatelessChild = (props) =&gt; {<br>  return (<br>    &lt;div&gt;{props.message}&lt;/div&gt;<br>  )<br>}</pre><h3>How to Fix jsx-no-bind Error</h3><p>Arrow functions are usually used in event handlers. If we use normal functions or class methods, this keyword is not bound to the current instance, it is undefined. By using .bind or arrow function, we can access other class methods through this. To fix the jsx-no-bind error while still keeping the handler function bound, we can either bind it in constructor, or use the experimental class property syntax, which can be transformed by <a href="https://babeljs.io/docs/plugins/transform-class-properties/">Babel</a>. More information can be found in React <a href="https://reactjs.org/docs/handling-events.html">official document</a>, and here is the <a href="https://github.com/jizhang/jsx-no-bind/blob/master/src/components/NoArgument.js">gist</a> of different solutions.</p><pre>export default class NoArgument extends React.Component {<br>  constructor() {<br>    this.handleClickBoundA = this.handleClickUnbound.bind(this)<br>    this.handleClickBoundC = () =&gt; { this.setState() }<br>  }</pre><pre>  handleClickUnbound() { /* &quot;this&quot; is undefined */ }</pre><pre>  handleClickBoundB = () =&gt; { this.setState() }</pre><pre>  render() {<br>    return (<br>      &lt;div&gt;<br>        // Error: jsx-no-bind<br>        &lt;button onClick={() =&gt; { this.setState() }}&gt;ArrowA&lt;/button&gt;<br>        &lt;button <br>           onClick={() =&gt; { this.handleClickUnbound() }}<br>        &gt;<br>          ArrowB<br>        &lt;/button&gt;<br>        &lt;button onClick={this.handleClickUnbound.bind(this)}&gt;<br>           Bind<br>        &lt;/button&gt;</pre><pre><br>        // No error:<br>        &lt;button onClick={this.handleClickBoundA}&gt;BoundA&lt;/button&gt;<br>        &lt;button onClick={this.handleClickBoundB}&gt;BoundB&lt;/button&gt;<br>        &lt;button onClick={this.handleClickBoundC}&gt;BoundC&lt;/button&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><p>For handlers that require extra arguments, e.g. a list of clickable items, things</p><pre>class Item extends React.PureComponent {<br>  handleClick = () =&gt; { this.props.onClick(this.props.item.id) }<br>  render() {<br>    return (<br>      &lt;li onClick={this.handleClick}&gt;{this.props.item.text}&lt;/li&gt;<br>    )<br>  }<br>}<br><br>export default class ListSeparate extends React.Component {<br>  handleClick = (itemId) =&gt; { alert(itemId) }<br>  render() {<br>    return (<br>      &lt;ul&gt;<br>        {this.props.items.map(item =&gt; (<br>          &lt;Item <br>             key={item.id} <br>             item={item} <br>             onClick={this.handleClick} <br>          /&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    )<br>  }<br>}</pre><p>This is a practice of separation of concerns, because now List only iterates the items, while Item takes care of rendering them. But this also adds a lot of codes, and make them hard to understand. We need to go through several handler functions to see what they actually do, while in the arrow function example, event handlers are co-located with the component, which is encouraged by React community.</p><p>Another approach is to use DOM <a href="https://developer.mozilla.org/en/docs/Web/API/HTMLElement/dataset">dataset</a> property, i.e. store argument in HTML data-* attribute, and retrieve it with eventargument in handler functions.</p><pre>export default class ListDataset extends React.Component {<br>  handleClick = (event) =&gt; { alert(event.target.dataset.itemId) }<br>  render() {<br>    return (<br>      &lt;ul&gt;<br>        {this.props.items.map(item =&gt; (<br>          &lt;li key={item.id} data-item-id={item.id} onClick={this.handleClick}&gt;{item.text}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    )<br>  }<br>}</pre><h4>Conclusion</h4><p>The anti-pattern is obvious when you realize it but it can still easily sneak in. The up-side of this is that if you screw up, like I have multiple times, it doesn’t break your app. It just performs bit slower and most of the time it doesn’t even matter but when it does I hope this article gives you some pointers on where to look.</p><blockquote>If you aren’t measuring, you can’t even know if your optimizations are better, and you certainly won’t know if they make things worse!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a4118d175b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Pre-Optimization — Don’t Abuse Keys!]]></title>
            <link>https://medium.com/@nids.nitesh/react-pre-optimization-dont-abuse-keys-8447f8419303?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8447f8419303</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 21:16:19 GMT</pubDate>
            <atom:updated>2019-03-29T08:40:00.931Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Pre-Optimization — Don’t Abuse Keys!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ig6pVj7s0uZXl1MvTOb42A.jpeg" /></figure><blockquote>Keys can turn your application into a rendering jackhammer.</blockquote><p>If you’ve ever got a chance to work with arrays or rendering list of components then you would’ve probably used key prop and might’ve seen below warning. (If you’re not lazy to look at the console 😝)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*JbV5-w5nAlOeiMJleIUUJQ.png" /><figcaption>You might want to avoid errors that look like this.</figcaption></figure><h3>Let’s see. What is key ?</h3><p>React key prop is a special prop that can be added to any component in order to explicitly tell React its identity. The common scenario where a component requires a key prop is within a list: React needs it in order to understand which items have been added, removed or, more generically, modified. This allows for advance DOM manipulations, preventing nodes from being destroyed and recreated for no reason. The key prop also prevents list items from loosing state between renders.</p><p>That’s why React introduced <em>key</em> prop. As stated in React’s official docs, every array element must have <strong>a unique</strong> key. See the following code snippet from React source code.</p><pre>/**<br> * Given a `prevElement` and `nextElement`, determines if the existing<br> * instance should be updated as opposed to being destroyed or replaced by a new<br> * instance. Both arguments are elements. This ensures that this logic can<br> * operate on stateless trees without any backing instance.<br> *<br> * @param {?object} prevElement<br> * @param {?object} nextElement<br> * @return {boolean} True if the existing instance should be updated.<br> * @protected<br> */<br><strong>function</strong> shouldUpdateReactComponent(prevElement, nextElement) {<br>  <strong>var</strong> prevEmpty = prevElement === null || prevElement === false;<br>  <strong>var</strong> nextEmpty = nextElement === null || nextElement === false;<br>  <strong>if</strong> (prevEmpty || nextEmpty) {<br>    <strong>return</strong> prevEmpty === nextEmpty;<br>  }</pre><pre>  <strong>var</strong> prevType = <strong>typeof</strong> prevElement;<br>  <strong>var</strong> nextType = <strong>typeof</strong> nextElement;<br>  <strong>if</strong> (prevType === &#39;string&#39; || prevType === &#39;number&#39;) {<br>    <strong>return</strong> nextType === &#39;string&#39; || nextType === &#39;number&#39;;<br>  } <strong>else</strong> {<br>    <strong>return</strong> (<br>      nextType === &#39;object&#39; &amp;&amp;<br>      prevElement.type === nextElement.type &amp;&amp;<br>      prevElement.key === nextElement.key<br>    );<br>  }<br>}</pre><p>On the last line, it’s simply checking that current element and next element’s type, as well as key, are same then it shouldn’t be updated. This way by using a key, React can easily determine whether to perform re-rendering or not.</p><h3>What should be the value of Key?</h3><p>In short, a Key should be:</p><ul><li><strong>Unique</strong> — A key cannot be identical to that of a <a href="https://facebook.github.io/react/docs/lists-and-keys.html#keys-must-only-be-unique-among-siblings">sibling component</a>.</li><li><strong>Static</strong> — A key should not ever change between renders.</li><li><strong>Predictable</strong> — You can always get the same key again if you want. That is, the key should not be generated randomly.</li></ul><h3>Index as a key is an anti-pattern</h3><p>Now, comes the interesting part. Most developers use <em>index </em>as <em>key. </em>Consider following example.</p><pre>{todos.map((item, index) =&gt; &lt;TODO {...todo} key={index} /&gt;)}</pre><p>It looks fine and also gets rid of original warning showing. What’s the problem here?</p><p>Well, It may break your application and also display wrong data. When you add or remove something from array or list, then element being inserted will get key already assigned to the old element. React assumes that element being inserted is old element because it gets an old key of some other element. So, React will simply skip re-rendering of that newly inserted element and we will see data of old element having this key.</p><p><strong>So why is this approach only <em>sometimes</em> bad?</strong></p><p>This approach is only risky if the array is somehow filtered, rearranged, or items are added/removed. If it is always static, then it’s perfectly safe to use. For example, a navigation menu like [&quot;Home&quot;, &quot;Products&quot;, &quot;Contact us&quot;] can safely be iterated through with this method because you&#39;ll probably never add new links or rearrange them.</p><p>In short, here’s when you can <strong>safely</strong> use the index as key:</p><ul><li>The array is static and will never change.</li><li>The array is never filtered (display a subset of the array).</li><li>The array is never reordered.</li><li>The array is used as a stack or LIFO (last in, first out). In other words, adding can only be done at the end of the array (i.e push), and only the last item can ever be removed (i.e pop).</li></ul><p>Had we instead, in the snippet above, <strong>pushed</strong> the added item to the end of the array, the order for each existing item would always be correct.</p><h3>Random unique keys</h3><pre>{todos.map((item, index) =&gt; &lt;TODO {...todo} key={Math.random()} /&gt;)}</pre><p>If we use some random value as a key (e.g Math.random()) then, our problem will be solved but there will be a problem of performance in large lists. Because every time every element will get a new key. So, there is no way for react to keep track of which element is older and which one is newer. So it will perform re-rendering for the whole list.</p><blockquote><em>Unstable keys (like those produced by </em><em>Math.random()) will cause many component instances and DOM nodes to be unnecessarily recreated, which can cause performance degradation and lost state in child components.</em></blockquote><h3>Best approach</h3><pre>{todos.map((item, index) =&gt; &lt;TODO {...todo} key={item.uniqueId} /&gt;)}</pre><p>This is arguably the <a href="https://facebook.github.io/react/docs/lists-and-keys.html#keys">best approach</a> because it uses a property that is unique for each item in the dataset. For example, if rows contains data fetched from a database, one could use the table&#39;s Primary Key (<em>which typically is an auto-incrementing number</em>).</p><blockquote><em>The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys</em></blockquote><blockquote>What’s a good value for a key? An easy way to answer this is to ask:when would <em>you</em> say an item is the “same” even if the order changed? — Dan Abramov</blockquote><p><strong>Rule of thumb: something unique is always better than index.</strong></p><p>Thanks for reading my post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8447f8419303" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wasted Render : This can slow down our React App]]></title>
            <link>https://medium.com/@nids.nitesh/wasted-render-this-can-slow-down-our-react-app-fdc5a476acbf?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdc5a476acbf</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Sun, 20 Jan 2019 11:28:15 GMT</pubDate>
            <atom:updated>2019-01-21T17:30:49.411Z</atom:updated>
            <content:encoded><![CDATA[<h3>Wasted Render : This can slow down our React App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJ2DFX57bEUV4FJGIXFi8w.png" /></figure><p>React is fast. Like, The Flash ⚡. The core team spends lots of time and money making sure that React only makes the changes to the DOM that actually need to be made based on changes in state. However, as developers, we need to be aware that the code we write and the way we write it have huge impacts on the performance of our applications. We can’t just expect the framework to be able to figure everything out</p><p>To make this article practical as possible, I choose Twitter sign-up page :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*3Xt6ILMmmUF3HzTRvE3COA.gif" /><figcaption>Twitter signup page</figcaption></figure><p>As you can see in the image, whenever I type type something, every single component get highlighted, it means our whole sign-up page is being re-rendered 😱</p><p>It is called “wasted” render. This is really bad because there’s really no reason for the entire component to be re-rendered when the change to be updated is in one small bit.</p><p>Identifying wasted renders in your react applications is the perfect start to identifying most performance issues. the simplest method is to toggle on the “highlight updates” option in the React dev tools.</p><p>This is one of the most common issues that affects performance in React is unnecessary render cycles. Fixing the issue is pretty simple. We simply need to short circuit the re-rendering for a subtree if we know that the subtree hasn’t changed.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtrBstxXuf8ceY%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtrBstxXuf8ceY%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FtrBstxXuf8ceY%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="266" frameborder="0" scrolling="no"><a href="https://medium.com/media/f25e034cd9bab4c2ab9d0e3c6cef5210/href">https://medium.com/media/f25e034cd9bab4c2ab9d0e3c6cef5210/href</a></iframe><p>No matter how small, rendering a component element tree takes some time (no matter how minute). The time for rendering gets larger as the component element tree increases.</p><p>The implication of this is that in your app you do not want React re-rendering your component element tree if it is not important. Let me show a quick example :</p><pre>// An app with a parent component Parent and 3 child components.</pre><pre>&lt;Parent&gt;<br>    &lt;ChildOne /&gt;<br>    &lt;ChildTwo /&gt;<br>    &lt;ChildThree /&gt;<br>&lt;/App&gt;</pre><p>The overall container component, Parent receives a certain prop. However, the sole reason for this is to pass the props down to component ChildThree.</p><p>Now, whenever the prop value in Parent changes, the entire children elements of Parent are re-rendered to compute a new element tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*bc0gkRY29iw6ATjWpRt5zA.png" /></figure><p>When the parent component receives new Props, every child element is re-rendered and a new tree returned. The components ChildTwo and ChildThree are also re-rendered even though they haven’t changed at all! They have not received any new props. This needless re-rendering.</p><p>In this example, ChildTwo and ChildThree need not re-render, but React doesn’t know this.There are many ways to deal with such issue.</p><h3><strong>How Pure </strong>Components<strong> can help:</strong></h3><pre>class PureComponetExample extends React.PureComponent {<br> render (){<br>   // Component Structure <br> }<br>}</pre><p>React gives you the ability to optimise component, by implementing shouldComponentUpdate function.</p><p>Next, you can decide should you re-render it on props and state change, or not. Pure-render-mixin or PureComponent just implements this function for you. And it is just impossible to generate it for a stateless component as long it is not a Component. It is just a function.</p><p>Actually, React uses that stateless component indirectly and it can perform necessary checks in Component Adapter. Actually — stateless components are very complex thing, and React expects them to be pure functions.</p><p>Pure components keep your application fast. Sometimes — more predictable, but often — less predictable, as long they change the way application works. The way it flows.</p><blockquote><em>Prefer PureComponent over Component, but never mutate your objects (and use other best practices)</em></blockquote><h3><strong>You can take care of any problem that comes your way:</strong></h3><h4>Don’t bind values in functions in render</h4><p>Say you have a list of items, each passing a unique parameter to parent method. In order to bind the parameter you’ve maybe done something like this:</p><pre>&lt;Form onSubmit={() =&gt; this.onSubmit(user.id)} /&gt;</pre><p>The problem is that every time the parent’s render method is called, a new function (with a new reference) is created to be passed to onSubmit. This has the side effect of changing the props on each child which in turn will cause them all to re-render, even if the data itself is all the same.</p><p>To get around this, only pass the reference to the parent’s prototype method to children. The child’s onSubmit prop will always have the same reference and never cause a needless re-render.</p><pre>&lt;Form onSubmit={this.onSubmit} userID={user.id} /&gt;</pre><p>Then in the child component create a class method that will reference its props:</p><pre>class Form extends PureComponent {<br>  ...<br>  onSubmit() {<br>    this.props.onSubmit(this.props.userID)<br>  }<br>  ...<br>}</pre><h4>Don’t use Spreading props</h4><pre>class Parent extends Component {<br>  render(){<br>     return &lt;Child {..restProps} /&gt; ;<br>  }<br>}</pre><p>You know the drill. Why is this bad?</p><p>You may be accidentally passing props that Parent doesn’t care about. When those props change, Child will re-render wastefully.</p><p><strong>Fix</strong>: Unless you’re writing some sort of higher-order-component, don’t be lazy and be explicit about the props that you are passing.</p><h3>That’s It</h3><p>We looked into most common terms in React development and demonstrated what they are and how useful they are. This will be very much rewarding if you put it into practice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdc5a476acbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prevent Sending HTTP Referer Headers from Your Website]]></title>
            <link>https://medium.com/front-end-weekly/prevent-sending-http-referer-headers-from-your-website-e30eecfe813a?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e30eecfe813a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[phishing-awareness]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 15:32:40 GMT</pubDate>
            <atom:updated>2019-01-04T16:08:03.449Z</atom:updated>
            <content:encoded><![CDATA[<p>Opening links in a new window is a generic method to navigate the users to another domain. We can achieve this using target=&quot;_blank&quot;. I’m sure everybody used the target with _blank value in some of his projects, but I’m not sure everybody knows the drawbacks of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*kEgvPQfOBvYFBo5s7KeOUw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><p>When any external link is opened with target=&quot;_blank&quot; then that external link will open in another new blank tab. Now, this page will open and follow the same process of the original page. This also means if the new external page has any performance issue like if it has high load time then this will also affect the original page performance. If you are open the same origin you have full access — to the document object too — on cross-origin this is disabled (window.opener.document), but you can still access the location object.</p><p><strong>It means that if you embed a link into your site or article which point to another page and opened in a new window. The target page can modify the original page in some way through JavaScript using </strong><strong>window.opener object</strong>.</p><blockquote>To see this in work, please navigate to this <a href="https://s.codepen.io/adamlaki/debug/dd4475e9a73052ad37d3e5f19f4bcb92">link</a></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fmx8YPPZC4u6zu%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fmx8YPPZC4u6zu%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fmx8YPPZC4u6zu%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="176" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a57f8e76e0aac3cb70ca8535c56c649/href">https://medium.com/media/4a57f8e76e0aac3cb70ca8535c56c649/href</a></iframe><p>So what happens here? After you click on the link (in the opened document), the browser opens the page which runs a script that using the window.opener object to modify the original page (which you come from). Plain dull but can be harmful.</p><p>The last question is: how we can disable this behavior? Use rel=&quot;noopener&quot; on every link which is using target=&quot;_blank&quot; and navigate to another document.</p><pre>&lt;a href=&quot;https://niteshsoni.info&quot; rel=&quot;noopener&quot;&gt;&lt;/a&gt;</pre><p>rel=&quot;noopener&quot; is used so that when a new window is created upon clicking a link, malicious javascript code running in the new window will not access your previous window via the window.opener attribute and will ensure it runs in a separate process.</p><p>In older browsers, you can use rel=&quot;noreferrer&quot;, attribute has the same effect, but will also prevent the Referer header from being sent to the new page</p><pre>&lt;a href=&quot;https://niteshsoni.info&quot; rel=&quot;noopener noreferrer&quot;&gt;&lt;/a&gt;</pre><p>rel=&quot;noreferrer&quot; is used so that when a user clicks on a hyperlink and is transferred to a new location, no referrer information will be leaked to the destination link. Meaning, it will not be possible for the destination to know when that user came from.</p><p>This also applies if you open the window through JavaScript window.open(); function because you also open a window. In this case, you have to clear the opener object:</p><pre>var newWindow = window.open();<br>newWindow.opener = null;</pre><p>In my view, there are no major downsides in applying the first solution (adding rel=&quot;noopener&quot;<em> </em>to every<em> </em>target=&quot;_blank&quot;<em> </em>link). This issue shows how easy it is to create loopholes in your web page security</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e30eecfe813a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/prevent-sending-http-referer-headers-from-your-website-e30eecfe813a">Prevent Sending HTTP Referer Headers from Your Website</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a realtime Desktop app using Electron and React]]></title>
            <link>https://medium.com/@nids.nitesh/build-a-realtime-desktop-app-using-electron-and-react-f076cee148ef?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f076cee148ef</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[electron]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 10:37:54 GMT</pubDate>
            <atom:updated>2018-11-19T10:37:54.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lr-oO7eEjVAsompNFxcVJA.png" /></figure><p>We are all victims of a revolution where building apps and websites becomes easier every single day and Electron js is definitely a part of this revolution.</p><blockquote>Electron is a framework for creating desktop applications with all the emerging technologies including JavaScript, HTML and CSS. Basically, Electron framework takes care of the hard parts so that you can focus on the core of the application and revolutionize its design.</blockquote><p>In this tutorial, I will be going over what you need and how to write a functional Electron app with React. Specifically, we will be:</p><ul><li>Setting up local environment for Electron and React</li><li>Writing code to render your app</li><li>Handle both react dev server and electron dev server</li></ul><p>Here are the steps :</p><ol><li><strong>Setup create-react-app</strong></li></ol><p><a href="https://github.com/facebook/create-react-app">GitHub - facebook/create-react-app: Set up a modern web app by running one command.</a></p><p><strong>2. Install electronJS</strong></p><pre>npm install --save-dev electron</pre><p><strong>3. Add </strong><strong>electron-starter.js file in root directory</strong></p><pre>const electron = require(‘electron’);<br>const app = electron.app;<br><br>const BrowserWindow = electron.BrowserWindow;</pre><pre>const path = require(‘path’);<br>const url = require(‘url’);</pre><pre>// Keep a global reference of the window object, if you don’t, the window will<br>// be closed automatically when the JavaScript object is garbage collected.<br>let mainWindow;</pre><pre>function createWindow() {<br>  // Create the browser window.<br>  mainWindow = new BrowserWindow({width: 800, height: 600});</pre><pre> // and load the index.html of the app.<br> const startUrl = process.env.ELECTRON_START_URL || url.format({<br>    pathname: path.join(__dirname, ‘/../build/index.html’),<br>    protocol: ‘file:’,<br>    slashes: true<br> });<br> mainWindow.loadURL(startUrl);</pre><pre> // Open the DevTools.<br> // mainWindow.webContents.openDevTools();</pre><pre> // Emitted when the window is closed.<br> mainWindow.on(‘closed’, function () {<br>    mainWindow = null<br> })<br>}</pre><pre>// This method will be called when Electron has finished<br>// initialization and is ready to create browser windows.<br>// Some APIs can only be used after this event occurs.<br>app.on(‘ready’, createWindow);</pre><pre>// Quit when all windows are closed.<br>app.on(‘window-all-closed’, function () {<br> // On OS X it is common for applications and their menu bar<br> // to stay active until the user quits explicitly with Cmd + Q<br> if (process.platform !== ‘darwin’) {<br>   app.quit()<br> }<br>});</pre><pre>app.on(‘activate’, function () {<br> // On OS X it’s common to re-create a window in the app when the<br> // dock icon is clicked and there are no other windows open.<br> if (mainWindow === null) {<br>   createWindow()<br> }<br>});</pre><p><strong>4. Add a main entry to </strong><strong>package.json for </strong><strong>electron-starter.js.</strong></p><pre>{<br>   “name”: “electro-reactro”,<br>   “version”: “0.1.0”,<br>   “private”: true,<br>   “author”: “Nitesh Soni”,<br>   “description”: “starter kit for react based desktop application”,<br>   “devDependencies”: {<br>      “electron”: “¹.4.14”,<br>      “react-scripts”: “².1.1”,<br>   },<br>   “dependencies”: {<br>      “react”: “¹⁵.6.2”,<br>      react-dom”: “¹⁵.4.2”<br>   },<br>   “main”: “./src/electron-starter.js”,<br>   “scripts”: {<br>      “start”: “react-scripts start”,<br>      “build”: “react-scripts build”,<br>      “test”: “react-scripts test — env=jsdom”,<br>      “eject”: “react-scripts eject”,<br>      “electron”: “electron .”<br>   },<br>   “browserslist”: [<br>      “&gt;0.2%”,<br>      “not dead”,<br>      “not ie &lt;= 11”,<br>      “not op_mini all”<br>   ]<br>}</pre><p><strong>5. Add relative path to </strong><strong>package.json for electron app</strong></p><pre><br> “homepage”: “./”,</pre><p><strong>6. Add foreman</strong></p><p>forman is process management tool which launch/manages both react dev server and electron dev server.</p><pre>npm install — save-dev foreman</pre><p>and add the following Procfile</p><pre>react: npm run start<br>electron : npm run electron</pre><p><strong>7. Add </strong><strong>electron-wait-react.js file to root directory</strong></p><p>We will keep a simple node script to electron-wait-react.jsthat waits react dev server to start, then starts electron server.</p><pre>const net = require(‘net’);<br>const port = process.env.PORT ? (process.env.PORT — 100) : 3000;</pre><pre>process.env.ELECTRON_START_URL = `<a href="http://localhost:${port}`">http://localhost:${port}`</a>;</pre><pre>const client = new net.Socket();</pre><pre>let startedElectron = false;<br>const tryConnection = () =&gt; client.connect({port: port}, () =&gt; {<br>   client.end();<br>   if(!startedElectron) {<br>      startedElectron = true;<br>      const exec = require(‘child_process’).exec;<br>      exec(‘npm run electron’);<br>   }<br> }<br>);</pre><pre>tryConnection();</pre><pre>client.on(‘error’, (error) =&gt; {<br>  setTimeout(tryConnection, 1000);<br>});</pre><p>8. In final step, will add following command to package.json</p><pre>“dev”: “nf start -p 3000”,</pre><p>and now we can execute:</p><pre>npm run dev</pre><p>If you’re lazy to do all of the above steps, just browse the example repo where you have everything ready.</p><p><a href="https://github.com/nidsnitesh/electro-reactro">nidsnitesh/electro-reactro</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f076cee148ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install web-app as native app]]></title>
            <link>https://medium.com/@nids.nitesh/how-to-install-web-app-as-native-app-f61473e94a88?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f61473e94a88</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Thu, 15 Nov 2018 19:13:12 GMT</pubDate>
            <atom:updated>2018-11-15T19:13:12.725Z</atom:updated>
            <content:encoded><![CDATA[<p>Add to Home screen (or A2HS for short) is a feature available in modern smartphone browsers that allows developers to easily and conveniently add a shortcut to their Home screen representing their favorite web app (or site) so they can subsequently access it with a single tap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*_1k9Sh7lpNjUrKB1gJ7uRg.png" /></figure><p>These technologies allow the app to be launched directly from the device’s home screen instead of starting the browser manually and typing in the URL. Your web app can sit next to native applications as first class citizens. It is therefore easier to access, and you can also specify that an app should run fullscreen without the surrounding browser chrome, making it feel even more like a native app.</p><p>To enable your app to be added to a Home screen, here are 3 easy step:</p><h3><strong>Step 1 : Create service worker file</strong></h3><p>A service worker is a programmable proxy, a script, that your browser runs in the background. It has the ability to intercept, handle http requests and also respond to them in various ways.</p><blockquote>The Service worker can be used to display the application shell, inform users that they are disconnected from the internet and serve up a page for the user to interact with once they are offline.</blockquote><p>create a blank service-worker.js file in your root folder. And you need to register the service worker in your app’s js file. we’ll have a piece of JavaScript code like so :</p><pre>&lt;script&gt;<br> if (‘serviceWorker’ in navigator) {<br>    console.log(“Will the service worker register?”);<br>    navigator.serviceWorker.register(‘service-worker.js’)<br>   .then(function(reg){<br>       console.log(“Yes, it did.”);<br>   }).catch(function(err) {<br>       console.log(“No it didn’t. This happened:”, err)<br>   });<br> }<br> &lt;/script&gt;</pre><p>The piece of code above checks if the browser supports service workers, and if it does, registers the service worker file.</p><h3>Step 2 : Create manifest file</h3><p>create manifest.json file in root folder. Add below tag in your html page header section :</p><pre>&lt;link rel=”manifest” href=”/manifest.json”&gt;</pre><p>Step 3 : Add configurations in manifest file<br>The web manifest is written in standard JSON format and should be placed somewhere inside your app directory (in the root is probably best) with the name manifest.json. It contains multiple fields that define certain information about the web app and how it should behave.</p><p>Here is the configurations we used.</p><pre>{<br> “name”: “Nitesh”,<br> “short_name”: “Nitesh Soni”,<br> “theme_color”: “#128c7e”,<br> “background_color”: “#ece5dd”,<br> “display”: “standalone”,<br> “Scope”: “/”,<br> “start_url”: “/”,<br> “icons”: [<br>   {<br>     “src”: “images/icons/icon-72x72.png”,<br>     “sizes”: “72x72”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-96x96.png”,<br>     “sizes”: “96x96”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-128x128.png”,<br>     “sizes”: “128x128”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-144x144.png”,<br>     “sizes”: “144x144”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-152x152.png”,<br>     “sizes”: “152x152”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-192x192.png”,<br>     “sizes”: “192x192”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-384x384.png”,<br>     “sizes”: “384x384”,<br>     “type”: “image/png”<br>   },<br>   {<br>     “src”: “images/icons/icon-512x512.png”,<br>     “sizes”: “512x512”,<br>     “type”: “image/png”<br>   }<br> ],<br> “splash_pages”: null<br>}</pre><p>In the above code you can replace your own value.</p><p>Most of the fields are self-explanatory, but let’s break down the document and explain them in detail:</p><p>name: The full name of your web app.<br>short_name: Short name to be shown on the home screen.<br>icons: A bunch of icon information — source URLs, sizes, and types. Be sure to include at least a few, so that one that fits best will be chosen for the user’s device.<br>start_url: The index document to launch when starting the app.<br>display: How the app is displayed; can be fullscreen, standalone, minimal-ui, or browser<br>theme_color: A primary color for the UI, used by operating system<br>background_color: A color for background, used during install and on the splash screen</p><p>However, if for some reason you still aren’t seeing the Add to Homescreen banner appear at the bottom of the page, there are a few things you might want to check. Firstly, for the A2HS banner to appear, a few criteria need to be met:</p><p>* Your site needs to be running over HTTPS, have a valid manifest file (with a start url and icon) and have an active service worker file.<br> You can validate your manifest <a href="https://manifest-validator.appspot.com/">here</a>.</p><ul><li>The user also has to have visited your site at least twice within the last five minutes. The reason for this is that if the banner appeared too many times it could be very spammy for the user. Those “install our native app” banners are bad enough on some websites already.</li></ul><p>If you’re using React and you’re lazy to do all of the above steps, just<a href="https://github.com/nidsnitesh/react-pwa-starter-kit"> browse the example</a> repo where you have everything ready.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f61473e94a88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding The Viewport Meta Tag]]></title>
            <link>https://medium.com/@nids.nitesh/understanding-the-viewport-meta-tag-b5ccd8c4f0e6?source=rss-65ccc08ee6c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5ccd8c4f0e6</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[media-queries]]></category>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nitesh Soni]]></dc:creator>
            <pubDate>Wed, 07 Nov 2018 10:04:11 GMT</pubDate>
            <atom:updated>2018-11-07T10:35:54.072Z</atom:updated>
            <content:encoded><![CDATA[<p>When working on a new web design one of things you need to think about is responsive design. Is the website you are about to make going to need a responsive design?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fb8ik5GvzWLMI5_TpBgzqw.png" /></figure><p>I think all external facing sites should take responsive design into consideration. There are some people who think that responsive design is not worth it as people on mobile devices can zoom in to see what they want, but I feel developers should make a website easy to use on any device.</p><blockquote><strong>The viewport meta element is what turns a regular website page into a responsive page, and it’s also one of the number one reason for StackOverflow questions on why their media queries are not working.</strong></blockquote><h3>What is the viewport element ?</h3><p>The viewport is a short tag that is included in the head of your HTML document that tells the browser how the page should be rendered. See the Best Practice example below</p><pre>&lt;meta name=”viewport” content=”width=device-width,initial-scale=1&quot;&gt;</pre><p>This is telling the browser to set the width of the content to the width of the device itself, and to scale that content to 1 on load.</p><h3><strong>Why do we need it?</strong></h3><p>When the iPhone was originally released Apple needed it to be suitable to consume websites the way they existed at the time. There was no way an internet browsing device was going to be successful if the websites that were being viewed were too big and the experience was poor.</p><p>To solve this problem Apple applied a neat trick within the safari mobile browser to tell the webpage that the content width was 960px — the targeted width for many websites at the time the first iPhone was released.</p><p>Changing the values in the viewport will allow you to customize how mobile devices render your website.</p><p>There are many options we can include in the content section of the meta viewport.</p><p><strong>Viewport Width (sets the width of the layout viewport)</strong></p><p>The width that you define in the viewport is like telling the browser this webpage is best viewed in this width. If you have setup a webpage which is best viewed on a iPhone then you will set the viewport to be 320px.</p><pre>&lt;meta name=”viewport” content=”width=320&quot;&gt;</pre><p>But this isn’t good for responsive designs as if you are viewing this page on a tablet your web page will be zoomed out to just view an area of 320px. The best thing to do for responsive design is to set the width of the viewport to be the same as whatever device is being used.</p><pre>&lt;meta name=”viewport” content=”width=device-width”&gt;</pre><p><strong>Viewport Scaling</strong></p><p>On mobile devices you can use a pinch gesture to zoom the pages in and out, but if you set the viewport to be the width of the device you don’t need to zoom in to see the web page. To make sure that you web page isn’t zoomed in when initially displayed you can use a property initial-scale to set the default zoom.</p><p>To make sure the user doesn’t need to zoom when visiting your page set this to a ratio of 1.</p><pre>&lt;meta name=”viewport” content=”initial-scale=1&quot;&gt;</pre><p>If you want to disable your user from scrolling at all you can setup a property maximum-scale to be 1 to make sure you can’t scale anymore.</p><p>When you access the website, top priority is maximum-scale=1, and it won’t allow the user to zoom.</p><pre>&lt;meta name=”viewport” content=”maximum-scale=1&quot;&gt;</pre><p>Minimum-scale defines the minimum zoom. This works the same as above, but it defines the minimum scale. This is useful, when maximum-scale is large, and you want to set minimum-scale.</p><pre>&lt;meta name=”viewport” content=”minimum-scale=1&quot;&gt;</pre><p>user-scalable= yes(default) to allow the user to zoom in or zoom out on the web page or user-scalable=no to prevent the user from zooming in or zooming out</p><pre>&lt;meta name=”viewport” content=”user-scalable=yes”/&gt;</pre><p>If you want to see some examples of using the different viewport sizes there is a good Github project which shows you multiple viewport setups. Clicking on the links is a mobile browser will show you how they look.</p><p><a href="http://andreasbovens.github.io/understanding-viewport/">Understanding viewport</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5ccd8c4f0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>