Posts

Understanding useRef and forwardRef in React — A Beginner’s Guide

When working with React, you often hear about useRef and forwardRef . At first, they can feel confusing: “Why do I need refs when I already have props and state?” This article will walk you through the why, how, and when of refs in React — with simple examples, analogies, and real use cases. 1. What is useRef ? Think of useRef as a sticky note inside your component. Whatever you write on it will still be there even after React re-renders your component. function App() { const inputRef = React.useRef<HTMLInputElement>(null); const focusInput = () => { inputRef.current?.focus(); }; return ( <div> <input ref={inputRef} placeholder="Type here..." /> <button onClick={focusInput}>Focus Input</button> </div> ); } useRef creates a box that holds a reference to the <input> DOM element. inputRef.current po...

Understanding Time and Space Complexity

Image
When writing code, one of the key considerations is efficiency—how quickly the program runs and how much memory it uses. These two concepts are measured by time complexity and space complexity . Understanding how different operations affect time and space complexity is crucial for optimizing algorithms. 1. Time Complexity Time complexity is a way to represent the amount of time an algorithm takes to complete as a function of the input size. The most common time complexities include: O(1) Constant Time : The operation takes the same amount of time, no matter the input size. O(log n) Logarithmic Time : The operation’s time grows logarithmically as input increases (e.g., binary search). O(n) Linear Time : The operation time grows linearly with the input size. O(n²) Quadratic Time : Time grows quadratically as the input size increases (e.g., nested loops). O(2ⁿ) Exponential Time : Time doubles with each additional input (e.g., some recursive algorithms). ...

Understanding Fibonacci: A Developer’s Perspective

Image
The Fibonacci sequence is one of the simplest and most fascinating concepts in mathematics. Its presence in nature, computer algorithms, and problem-solving makes it an ideal case study for understanding various programming concepts. In this blog, we will explore Fibonacci from both a mathematical and a developer's standpoint, covering recursive vs iterative approaches , the importance of time and space complexity , and the implications of shallow vs deep copying along with the behavior of primitives and objects . 1. The Mathematics Behind Fibonacci The Fibonacci sequence starts with 0 and 1, with each subsequent number being the sum of the two preceding ones. Mathematically, this is expressed as: F(n) = \begin{cases} 0 & \text{if } n = 0, \\ 1 & \text{if } n = 1, \\ F(n-1) + F(n-2) & \text{if } n \geq 2 \end{cases} F(0) = 0 F(1) = 1 F(2) = 1 F(3) = 2 and so ...

Highcharts: A 10 minutes overview.

Image
A Norway-based company 'Highsoft' offering charting library written in pure javascript. Its a major addon to web applications requires interactive charts. Currently they're supporting many chart types including line, area, column, bar, pie, scatter, bubble, gauge, spline, areaspline and polar etc. Already Highcharts is providing a descriptive demo page considering all examples ( Highcharts Demos ). The pupose of the article only to understand maximum aspects in a view. Features : Compatible with all major browsers, it also provides features like DateTime support, Export (PDF/ PNG/ JPG / SVG), Print and Zoomablity etc. Installation: Its a single file downloadable from (https://www.highcharts.com/). Also packages through npm and Bower are avalable. We may load file on our domain or use CDN version. Load files from your own domain (Insert in html head) <script src = "/js/highcharts.js"> CDN Version (Insert in html head) <script src = ...

Regular Expression Fundamentals : Practical Examples

Image
Regular Expression Fundamentals : Practical Examples - LifeAdda Before getting into regular expressions, first needs to understand the data on we're planning to apply regular expressions. Below are few important data types : Characters a-z & A-Z Digits 0-9 Words letter, digit or underscore collection White-space white space is any character or series of characters that represent horizontal (Spacebar, Tab) or vertical space (Enter) in typography. Boundaries The word boundary is the position of word (letter, digit or underscore collection) Anchors ^ and $ called anchors Basic Meta-characters : * A line terminator is a one- or two-character sequence that marks the end of a line of the input character sequence. The following are recognized as line terminators: A newline (line feed) character ('\n') A carriage-return character followed immediately by a newline character ("\r\n") A standalone carriage-return character ('\r'...