Posts

Showing posts from March, 2018

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...

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'...