Posts

Showing posts from March, 2025

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

A Complete Tutorial: Using RabbitMQ + Celery with Multiple Django Projects

In this post, we’ll walk through how to set up RabbitMQ on one server and run Celery across multiple Django projects, with clean project isolation, scalable architecture, and best practices. ✅ Step 1: Install RabbitMQ (Server A) ➡️ On Ubuntu (Server A): sudo apt update sudo apt install rabbitmq-server -y sudo systemctl enable rabbitmq-server sudo systemctl start rabbitmq-server ➡️ Enable RabbitMQ Management UI: sudo rabbitmq-plugins enable rabbitmq_management Visit: http://server-a-ip:15672 (default guest/guest). ➡️ Create RabbitMQ User: sudo rabbitmqctl add_user admin strongpasswordhere sudo rabbitmqctl set_user_tags admin administrator sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" sudo rabbitmqctl delete_user guest # For security ➡️ Open Ports: 5672 (for Celery workers) 15672 (for admin UI, restricted IPs recommended) ✅ Step 2: Project Structure (Multiple Django Projects Example) /var/www/ ├── project_...