Facebook Twitter LinkedIn RSS
    Trending
    • Konga launches Berekete Sales with 50% discounts across major categories
    • Nigeria’s $2 billion fibre ambition got $122m European boost
    • SERAP urges FCCPC to probe Google, Meta and others over rights infringement
    • Experts at Newmark Webinar urge Africa to build custom AI healthcare solutions
    • Interswitch unveils new campaigns for Quickteller & Verve
    • FlashChange Set to Host International Women’s Day Webinar
    • Leo Stan Ekeh at 70: Tech Pioneer Honours Tinubu, Obasanjo and Global Tech Community
    • Analyzing MTN Nigeria’s 2025 historic rebound and the 2026 outlook
    Facebook Twitter LinkedIn
    ITPulse.com.ngITPulse.com.ng
    • News
    • Interviews
    • Blogs
    • Analysis
    • Opinion
    • Videos
    • Press Releases
    • Pictures
    • Advertise
    ITPulse.com.ngITPulse.com.ng
    Home»Blogs»React Optimization: Strategies to Improve Performance, By Ofoefule Christian Ifeanyi
    Blogs 6 Mins Read

    React Optimization: Strategies to Improve Performance, By Ofoefule Christian Ifeanyi

    mmBy ITPulseNovember 7, 20223K Views
    Facebook Twitter WhatsApp Pinterest LinkedIn Reddit Tumblr Email
    Ofoefule Christian Ifeanyi
    Ofoefule Christian Ifeanyi
    Share
    Facebook Twitter LinkedIn Pinterest Email

    As software developers, we always want to create high-performing applications and write more efficient code as we ascend the ladder of expertise. React, a popular library known for its efficient rendering, optimization techniques play a critical role in ensuring a positive user experience.

    In this article, we will be exploring some strategies and techniques in React that can improve your application’s performance.

    Table of Contents

    Toggle
    • The Foundation: Understanding React Rerendering
      • Code Illustration: Unveiling the Rerendering Challenge
    • Optimization Strategies
      • 1. Keep Component State Local Where Necessary
      • 2. Memoizing React Components
      • 3. Code-Splitting with Dynamic Import
      • 4. Windowing or List Virtualization in React
      • 5. Lazy Loading Images in React
    • Additional Tips and Considerations

    The Foundation: Understanding React Rerendering

    React components automatically rerenders when there is a change in their state or props. While this behaviour is beneficial, it can lead to performance issues if not managed carefully.

    Consider a scenario where a parent component rerenders. In React’s default behaviour, all of its child components, even those with unchanged states or props, will also rerender. This behaviour, though intuitive, can result in unnecessary performance overhead, particularly for components with expensive computations during each render.

    Code Illustration: Unveiling the Rerendering Challenge

    The code sample below shows that whenever a parent component rerenders, all of its child components rerender regardless of whether a prop passes to them or not.

    
        	import { useState } from "react";
    
        	export default function App() {
            	const [input, setInput] = useState("");
    
            	return (
                	<div>
                    	<input
                        	type="text"
                        	value={input}
                        	onChange={(e) => setInput(e.target.value)}
                    	/>
                    	<h3>Input: {input}</h3>
                    	<ChildComponent />
                	</div>
            	);
        	}
    
        	export function ChildComponent() {
            	console.log("child component is rendering");
            	return <div>This is child component.</div>;
        	}
    
    
    	

    In this example, as we type into the input field, the ChildComponent rerenders with each keystroke, this can cause a huge performance issue especially when the child component performs an expensive computation each time it renders.

    Optimization Strategies

    1. Keep Component State Local Where Necessary

     

    Since we know that an update in the parent component causes both parent and child components to rerender, we can ensure that a component renders only when necessary, by extracting the state and making it local to that component.

    Here we refactor the code:

    
        	import { useState } from "react";
    
        	export default function App() {
            	return (
                	<div>
                    	<FormInput />
                    	<ChildComponent />
                	</div>
            	);
        	}
    
        	function FormInput() {
            	const [input, setInput] = useState("");
    
            	return (
                	<div>
                    	<input
                        	type="text"
                        	value={input}
                        	onChange={(e) => setInput(e.target.value)}
                    	/>
                    	<h3>Input text: {input}</h3>
                	</div>
            	);
        	}
    
        	function ChildComponent() {
            	console.log("child component is rendering");
            	return <div>This is child component.</div>;
        	}
    	

    In this refactored code, only the component using the state (FormInput) rerenders when the state changes, preventing unnecessary rerenders in other components.

    This is great, however sometimes we cannot avoid having a state in a global component and pass it down to child components as a prop, for such cases, we can employ other techniques.

    2. Memoizing React Components

    Memoization is a powerful optimization technique that caches the result of a rendered component and returns the cached result if the input remains the same. React provides the React.memo() function to memoize functional components.

    
    	const ChildComponent = React.memo(function ChildComponent({ count }) {
        	console.log(“child component is rendering”);
        	return (
            	<div>
                	<h2>This is a child component.</h2>
                	<h4>Count: {count}</h4>
            	</div>
        	);
    	});
    	

    In the above example, using React.memo() ensures that the child component only rerenders when its props (primitive data) changes. However, if we were passing down an object, array or a function as props, React.memo will not work and the child component will rerender.

    This happens because the object (or array or function) is redefined on each new render, making the memo function to see it as a change(or updated object) causing it to rerender the component.

    To prevent the function from always redefining, we can wrap it in a useCallback Hook and pass that as the prop instead of the raw function itself.

    
        		const incrementCount = React.useCallback(() => setCount(count + 1), [count]);
    	

    It is important to note that memoization comes with a memory cost, so we are trading memory space for time, hence we should use this technique only when necessary.

    3. Code-Splitting with Dynamic Import

    As your React application grows, loading the entire codebase to users at once can result in increased load times. Code-splitting allows us to split a large bundle file into multiple chunks using dynamic import() followed by lazily loading of these chunks on demand with React.lazy(). Hence we can refactor to:

    Hence we can refactor from this:

    
        	import Home from "./components/Home";
        	import About from "./components/About";
    	

    to this:

    
        		const Home = React.lazy(() => import("./components/Home"));
    const About = React.lazy(() => import("./components/About"));
    	

    This syntax tells React to load each component dynamically. So when a user follows a link to the home page, for instance, React only downloads the file for the requested page instead of loading a large bundle file for the entire application.

    After the import, we must render the lazy components inside a Suspense component like so:

    
        	<React.Suspense fallback={<p>Loading page...</p>}>
            	<Route path="/" exact>
                	<Home />
            	</Route>
            	<Route path="/about">
                	<About />
            	</Route>
        	</React.Suspense>
    	

    The Suspense component allows us to display a loading text or indicator as a fallback while React waits to render the lazy component in the UI.

    4. Windowing or List Virtualization in React

    Rendering a large list in its entirety, whether or not items are visible, can lead to performance issues. Windowing, or list virtualization, involves rendering only the visible portion of the list and dynamically rendering the remaining items as the user scrolls.

    Libraries like react-window and react-virtualized provide efficient windowing implementations for React.

    5. Lazy Loading Images in React

    Similar to windowing, lazy loading images involves rendering images only when they are about to become visible in the viewport. Libraries like react-lazyload and react-lazy-load-image-component offer solutions for lazy loading images in React.

    Additional Tips and Considerations

    1. Images and Media Files Optimization:
      • Resize images and limit upload sizes.
      • Use Content Delivery Networks (CDNs) like Cloudinary.
      • Apply compression and optimization techniques for media files.
    2. State Management:
      • Favour the Context API mixed with useReducer over Redux because with context api you use less javascript, its part of react js library, but with redux, you import more javascript libraries.
    3. UI Libraries Usage:
      • Avoid importing entire UI libraries when only a few components are needed.
      • Consider lightweight options like Tailwind CSS for optimised CSS.
    4. Lazy Loading for Most Things:
      • Load data and content on demand based on routes.
      • Optimise resource usage by loading only what is necessary for the current view.
    5. Progressive Web Apps (PWAs):
      • While PWAs offer benefits, be mindful of the performance cost due to increased code shipping.
    6. Use Unique Keys in Components:
      • When mapping through components, ensure each has a unique key to help React identify components efficiently.
    7. Memoization and Callbacks:
      • Utilise memoization and callbacks to speed up function calls where applicable.

     

    In conclusion, optimising React applications requires careful consideration of component states, memoization, code-splitting, windowing, and lazy loading. By incorporating these strategies and tips into your development workflow, you can ensure that your React applications deliver a responsive user experience. Happy optimising!

    Ofoefule Christian Ifeanyi React optimization
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    mm
    ITPulse
    • Website
    • Facebook
    • Twitter
    • LinkedIn

    ITPulse is a wholly information technology communication (ICT) news website, with a special focus on the African continent. The website provides up-to-date biz-tech news, analysis and comprehensive and thorough insight into the continent's ICT terrain

    Related Posts

    LG Electronics improves student welfare with solar-powered borehole project in Warri

    February 27, 2026

    From Dinner to Spontaneous Trips, PalmPay Couples Show How Love Is Funded Digitally

    February 25, 2026

    LG Nigeria launches nationwide search for oldest working TV, rewards loyalty with AI QNED upgrade

    February 17, 2026

    Leave A Reply Cancel Reply

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    Latest Posts

    Konga launches Berekete Sales with 50% discounts across major categories

    March 3, 2026

    Nigeria’s $2 billion fibre ambition got $122m European boost

    March 3, 2026

    SERAP urges FCCPC to probe Google, Meta and others over rights infringement

    March 2, 2026
    About
    About

    Itpulse.com.ng is a wholly information technology communication (ICT) news website, with special focus on the African continent. The website provides up-to-date biz-tech news, analysis and a comprehensive and thorough insight info the continent's ICT terrain.

    Contact us: editorial@itpulse.com.ng

    Facebook Twitter LinkedIn RSS
    Latest Posts

    Konga launches Berekete Sales with 50% discounts across major categories

    March 3, 2026

    Nigeria’s $2 billion fibre ambition got $122m European boost

    March 3, 2026

    SERAP urges FCCPC to probe Google, Meta and others over rights infringement

    March 2, 2026
    Popular Posts

    Galaxy Backbone clarifies status of GOVMAIL, confirms over 150,000 active government email accounts

    February 27, 2026

    SERAP urges FCCPC to probe Google, Meta and others over rights infringement

    March 2, 2026

    Experts at Newmark Webinar urge Africa to build custom AI healthcare solutions

    March 2, 2026
    © 2017 - 2026 Itpulse.
    • Terms & Conditions
    • Privacy Policy
    • Advertise
    • Contact Us

    Type above and press Enter to search. Press Esc to cancel.