Code With Riad

Code With Riad

Share

๐Ÿ‘จโ€๐Ÿ’ป Riad Mahamud | MERN Stack Developer
๐Ÿš€ Sharing code tips, dev projects & modern web solutions.

Photos from Code With Riad's post 06/11/2025

โšก Day 37 of my React.js Journey

Todayโ€™s topic: Building a Custom Hook โ€” useDebounce

When a user types fast (like in a search bar), we donโ€™t want to call the API on every keystroke.
๐Ÿ‘‰ We โ€œdebounceโ€ the input โ€” wait for the user to stop typing before running the logic.

Letโ€™s build it! ๐Ÿ‘‡

import { useState, useEffect } from "react";

function useDebounce(value, delay = 500) {
const [debouncedValue, setDebouncedValue] = useState(value);

useEffect(() => {
const handler = setTimeout(() => setDebouncedValue(value), delay);
return () => clearTimeout(handler);
}, [value, delay]);

return debouncedValue;
}

// Usage
function Search() {
const [query, setQuery] = useState("");
const debouncedQuery = useDebounce(query, 600);

useEffect(() => {
if (debouncedQuery) console.log("Search for:", debouncedQuery);
}, [debouncedQuery]);

return setQuery(e.target.value)} placeholder="Search..." />;
}

โœ… Why useDebounce matters:

Prevents unnecessary API calls

Boosts performance

Creates a smoother user experience

๐Ÿ’ก Used in search bars, live filters, or form validations!

Tomorrow: Building a Custom Hook โ€” usePrevious (track previous values) ๐Ÿ”„

Photos from Code With Riad's post 25/10/2025

๐Ÿงฉ Day 35 of my React.js Journey

Todayโ€™s topic: Custom Hooks โ€” Reusing Logic Like a Pro

React Hooks like useState and useEffect are greatโ€ฆ but what if you need the same logic in multiple components?
๐Ÿ‘‰ Thatโ€™s where Custom Hooks come in.

They let you extract and reuse stateful logic cleanly.

Example:

import { useState, useEffect } from "react";

function useFetch(url) {
const [data, setData] = useState(null);

useEffect(() => {
fetch(url)
.then(res => res.json())
.then(setData);
}, [url]);

return data;
}

// Usage
function Users() {
const users = useFetch("https://jsonplaceholder.typicode.com/users");
return {JSON.stringify(users, null, 2)};
}

โœ… Why use Custom Hooks:

Reuse logic without repeating code

Keep components clean

Share easily across projects

๐Ÿ’ก Naming rule: always start with use (e.g., useAuth, useForm, useDarkMode)

Tomorrow: Building a Custom Hook โ€” useLocalStorage ๐Ÿง 

Photos from Code With Riad's post 08/10/2025

๐Ÿš€ Day 34 of my React.js Journey

Todayโ€™s topic: Advanced Pattern โ€” React.lazy + Suspense for Dynamic Imports

When your app grows, you donโ€™t want to load every component at once.
๐Ÿ‘‰ Thatโ€™s where code-splitting comes in using React.lazy() and Suspense.

It lets React load components only when needed, improving performance and reducing bundle size.

Example:

import React, { Suspense } from "react";

const Profile = React.lazy(() => import("./Profile"));

function App() {
return (



);
}

โœ… How it helps:

Loads big components on demand

Boosts initial load speed

Perfect for routes, modals, and dashboard sections

๐Ÿ’ก Pro tip: Combine with React Router to lazy-load entire pages!

Tomorrow: Custom Hooks โ€” Reusing Logic Like a Pro ๐Ÿง 

Photos from Code With Riad's post 06/10/2025

โš™๏ธ Day 33 of my React.js Journey

Todayโ€™s topic: Performance Optimization with React.memo & useCallback

As apps grow, unnecessary re-renders can slow things down. React gives us two great tools to fix that:

๐Ÿง  React.memo

Prevents a component from re-rendering unless its props change.

const Child = React.memo(({ value }) => {
console.log("Rendered");
return {value};
});

โšก useCallback

Prevents a function from being recreated on every render.

function Parent() {
const [count, setCount] = useState(0);
const handleClick = useCallback(() => setCount(c => c + 1), []);
return ;
}

โœ… Why this matters:

Keeps your app fast

Reduces wasted re-renders

Crucial for lists, forms, and heavy UIs

๐Ÿ’ก Pro tip: Use them when needed โ€” overusing can make debugging harder.

Tomorrow: React.lazy + Suspense for Dynamic Imports (Advanced Pattern) ๐Ÿš€

Photos from Code With Riad's post 03/10/2025

โœ… Day 32 of my React.js Journey

Todayโ€™s topic: Todo App with Context + useReducer

Yesterday we learned useReducer. Today, letโ€™s combine it with Context API to manage global state-perfect for a Todo App.

Example:

import React, { createContext, useReducer, useContext } from "react";

const TodoContext = createContext();

function todoReducer(state, action) {
switch (action.type) {
case "add":
return [...state, { id: Date.now(), text: action.text }];
case "remove":
return state.filter(todo => todo.id !== action.id);
default:
return state;
}
}

function TodoProvider({ children }) {
const [todos, dispatch] = useReducer(todoReducer, []);
return (

{children}

);
}

function TodoList() {
const { todos, dispatch } = useContext(TodoContext);
return (

dispatch({ type: "add", text: "New Task" })}>
Add Todo


{todos.map(todo => (

{todo.text}
dispatch({ type: "remove", id: todo.id })}>
โŒ


))}


);
}

export default function App() {
return (



);
}

๐Ÿš€ With this approach:

Context provides global state

Reducer manages complex updates

Any component can add/remove todos

Tomorrow: React.memo & useCallback โ†’ optimize performance.

Photos from Code With Riad's post 02/10/2025

๐Ÿ“ Day 31 of my React.js Journey

Todayโ€™s topic: useReducer Hook

When state management gets complex (multiple values, deep updates), useState can become messy.
๐Ÿ‘‰ Thatโ€™s where useReducer shines.

Itโ€™s like a mini Redux built into React.

Example:

import React, { useReducer } from "react";

function reducer(state, action) {
switch (action.type) {
case "increment":
return { count: state.count + 1 };
case "decrement":
return { count: state.count - 1 };
default:
return state;
}
}

function Counter() {
const [state, dispatch] = useReducer(reducer, { count: 0 });

return (

Count: {state.count}
dispatch({ type: "increment" })}>+
dispatch({ type: "decrement" })}>-

);
}

โœ… Why use useReducer?

Keeps logic organized in one reducer function

Easy to scale for complex state

Pairs perfectly with Context API for global state

Tomorrow: Building a Todo App with Context + Reducer ๐Ÿ› ๏ธ

Photos from Code With Riad's post 01/10/2025

๐ŸŽฏ Day 30 of my React.js Journey โ€“ Milestone Post ๐Ÿš€

Todayโ€™s topic: Context API Deep Dive

React apps often suffer from โ€œprop drillingโ€ โ€” passing props down multiple levels.
๐Ÿ‘‰ The Context API solves this by sharing data across components without manually passing props.

Example:

import React, { createContext, useContext, useState } from "react";

const ThemeContext = createContext();

function App() {
const [theme, setTheme] = useState("light");

return (



);
}

function Toolbar() {
const { theme, setTheme } = useContext(ThemeContext);
return (
setTheme(theme === "light" ? "dark" : "light")}>
Current Theme: {theme}

);
}

โœ… Benefits of Context:
Share state globally without prop drilling
Great for themes, authentication, language settings, etc.
Cleaner & more maintainable code

โš ๏ธ Use carefully: too much context can make debugging harder โ†’ consider Redux, Zustand, or Jotai for larger apps.

๐ŸŒŸ 30 Days Recap:
โœ”๏ธ Components & Props
โœ”๏ธ Hooks (useState, useEffect, useContext, etc.)
โœ”๏ธ React Router basics
โœ”๏ธ Performance (lazy loading, error boundaries, portals)

Next chapter โ†’ Advanced Patterns & State Management ๐Ÿ”ฅ

Photos from Code With Riad's post 29/09/2025

๐Ÿšช Day 29 of my React.js Journey

Todayโ€™s topic: React Portals

By default, React renders components inside the root DOM node. But sometimes, we need to render outside of it (like modals, tooltips, or dropdowns).
๐Ÿ‘‰ Thatโ€™s where Portals come in.

Example:

import ReactDOM from "react-dom";

function Modal({ children }) {
return ReactDOM.createPortal(
{children},
document.getElementById("modal-root")
);
}

โœ… Benefits of Portals:

Keep components logically in React tree but render outside DOM hierarchy

Solve z-index issues with modals/popups

Improve accessibility (focus trapping, screen readers)

So next time your modal breaks layout โ€” use Portals instead of hacks. ๐Ÿš€

Tomorrow: Context API Deep Dive โ€” when and how to use it.

Photos from Code With Riad's post 28/09/2025

๐Ÿ›ก๏ธ Day 28 of my React.js Journey

Todayโ€™s topic: Error Boundaries in React

Even the best React apps can crash because of runtime errors. To avoid breaking the entire UI, React provides Error Boundaries.

๐Ÿ‘‰ Error Boundaries are React components that catch errors in their child components and display a fallback UI instead.

Example:

class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError() {
return { hasError: true };
}

componentDidCatch(error, info) {
console.error("Error caught:", error, info);
}

render() {
if (this.state.hasError) {
return Something went wrong!;
}
return this.props.children;
}
}

Usage:





โœ… Benefits:

Prevents full app crashes

Shows graceful fallback UI

Helps with debugging in production

โš ๏ธ Note: Error Boundaries do not catch errors in event handlers, async code, or server-side rendering.

Tomorrow: React Portals โ€” rendering outside the root div.

25/09/2025

๐Ÿš€ New JavaScript Project Completed โ€“ Sprite Animation with Multiple Effects! ๐ŸŽจโœจ

I recently built a simple sprite animation using JavaScript where a small plant comes to life ๐ŸŒฑ with different animation effects:

โœ… Grow โ€“ Smooth scaling animation
โœ… Wink โ€“ Playful flicker effect
โœ… Float โ€“ Gentle floating motion
โœ… Hide โ€“ Seamless fade-out transition
โœ… All Animations โ€“ Combined effects for extra fun!

This project was a great way to practice DOM manipulation, CSS transitions, and JavaScript event handling. ๐ŸŽฏ
It also shows how powerful even simple animations can be in creating interactive and engaging user experiences.

๐Ÿ’ก Whether itโ€™s a small web app, a game, or a playful UI component, animations help improve UX and keep users engaged.

๐Ÿ‘‰ If youโ€™re passionate about creative coding or want to make your websites more interactive and fun, letโ€™s connect!

Want your business to be the top-listed Advertising & Marketing Company in Panchagarh?
Click here to claim your Sponsored Listing.

Category

Address

Panchagarh
5000