Posts

Showing posts from December, 2024

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

How to Install and Manage PostGIS with a Non-Superuser Role

Image
Prerequisite: PostgreSQL Version This guide assumes you are using PostgreSQL version 14 or later, which supports the necessary commands for PostGIS installation and management. Ensure your PostgreSQL server is up-to-date before proceeding. This guide ensures that PostGIS is installed and configured properly for a specific user, such as administrator , while avoiding common issues. 1. Ensure Superuser Access sudo -i -u postgres psql --dbname=financethat 2. Create a Role for PostGIS Management CREATE ROLE administrator WITH LOGIN PASSWORD 'your_secure_password'; GRANT ALL PRIVILEGES ON DATABASE financethat TO administrator; 3. Install PostGIS To install PostGIS on Ubuntu, first ensure you have the required PostgreSQL version installed. Then, use the following commands: sudo apt update sudo apt install postgis postgresql-14-postgis-3 Replace 14 with your PostgreSQL version if different. After installation, enable PostGIS in...