logo

Blog Posts

Welcome to my blog! Here youll find articles, tutorials, and insights on web development, programming, and technology.

image

Optimizing Data Fetching in React using React.use

When working with React component, managing data fetching efficiently is crucial to providing a smooth and responsive user experience. In many cases using React.use or React.useEffect for fetching data can lead to multiple redundant requests, impacting both performance and resource usage. In this post, we’ll explore how to implement a custom caching mechanism to prevent unnecessary fetches while using React.Suspense and React.ErrorBoundary to handle loading states and errors.

5 min readRead More
image

Understanding React's useSyncExternalStore

React 18 introduced a new hook called useSyncExternalStore to help manage state that is external to React components. This hook is useful for integrating with external libraries or APIs that manage their own state

10 min readRead More
image

Mastering Custom Hooks in React

If you're diving deep into React, you've likely encountered custom hooks. These powerful tools enable developers to encapsulate complex logic and promote reusability across components

15 min readRead More
image

Event Capturing and Bubbling in React

When working with React, understanding how events propagate through the DOM is crucial for building interactive and responsive user interfaces.

5 min readRead More
image

Understanding Composition To Avoid Prop Drilling

The composition and Layout Components Pattern helps to avoid prop drilling and makes the code more readable and maintainable

5 min readRead More
image

Compound Components Pattern in React

The Compound Components Pattern allows you to create a collection of component that implicitly share state and behavior without the need to pass props down the component tree

4 min readRead More
image

Understanding React's flushSync API

React's automatic batching of state updates is a powerful feature that optimizes performance by reducing the number of re-renders. However

9 min readRead More
image

Unlocking the Power of Imperative Handles

When working with React, sometimes we need allows child components to to expose certain function or properties to the parent component or other child components

5 min readRead More
image

Dynamic Form Component in React

This is a dynamic form that can be used to create any form. by passing array of objects to the dataFields prop.

5 min readRead More
image

Controlled and Uncontrolled Components

Controlled components and uncontrolled components are two ways to manage form data. In a controlled component, the form data is handled by a React component. The form data is stored in the component's state and is updated through the component's setState method. the benefit of using a controlled component is that you have full control over the form data. You can validate the form data, manipulate the form data, and perform other operations on the form data. In an uncontrolled component, the form data is handled by the DOM itself. The form data is stored in the DOM, and is accessed through the DOM's API. In an uncontrolled component, the component does not manage the form data directly. the benefit of using an uncontrolled component is that you do not need to write as much code as you would with a controlled component. or for simple form with limited interaction You can also use uncontrolled components to integrate with third-party libraries that require direct access to the DOM. However, uncontrolled components are not as flexible as controlled components, and you may run into issues with form data

5 min readRead More
image

Enhancing State Management

create a custom React hook useLocalStorage to manage state with local storage , ensuring State Persistence and Synchronization across multiple tabs.

5 min readRead More
image

Higher Order Components in React (HOC)

The Higher Order Component (HOC) Pattern in React is a design pattern that allows you to reuse component logic. A higher-order component is a function that takes a component and returns a new component with additional props. HOCs are a powerful tool for code reuse and abstraction in React.

5 min readRead More
image

Understanding React Keys and Their Importance

The key prop in React uniquely identifies elements within a list or dynamically rendered components. It ensures React can track which elements have changed, been added, or removed, allowing for efficient DOM updates.

5 min readRead More
image

Latest React Features You Should Know

The Latest Ref Pattern enables you to reference the most recent value of props, state, or callback without including it in the dependency array when using it inside a useEffect

5 min readRead More
image

Partial Component pattern in React

This pattern is used to create a component that can be used as a partial component in other components. This pattern is useful when you have a component that is used in multiple places in your application, and you want to avoid duplicating the code for that component.

2 min readRead More
image

React Components with Default Props

When building reusable React components, one challenge developers often face is balancing flexibility with simplicity. For example, how do you provide sensible defaults while still allowing the consumers of your component to customize its behavior? The solution lies in leveraging default props effectively. In this article, we’ll discuss how to implement default props in React components to make them adaptable and user-friendly without compromising flexibility.

2 min readRead More
image

Understanding React createPortal in depth

React.createPortal is a method provided by React to render components outside the DOM hierarchy of their parent component. It allows you to mount a child node into a different part of the DOM, independent of where it is declared in your React component tree.

3 min readRead More