How to show loading state in React

Displaying loading states is crucial for providing visual feedback to users during asynchronous operations like API calls or data fetching in React applications. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented loading states in countless production components. From my expertise, the most effective approach is using useState to track loading status combined with conditional rendering to display appropriate UI. This creates a smooth user experience that keeps users informed about ongoing operations.

Use useState to track loading status and conditionally render loading UI.

const [loading, setLoading] = useState(false)

return loading ? <div>Loading...</div> : <div>Content loaded</div>

Here the loading state boolean controls what content is rendered. When loading is true, a loading message displays. When false, the actual content appears. Set setLoading(true) before starting async operations and setLoading(false) when they complete to provide real-time feedback to users about the application’s state.

Best Practice Note:

This is the same loading pattern we use in CoreUI components for data tables and form submissions. Consider using loading spinners or skeleton loaders instead of plain text for a more polished user experience, and always handle error states alongside loading states.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Genius Bootstrap Admin Template
Genius Bootstrap Admin Template

How to Position a Context Menu Opened from the Keyboard
How to Position a Context Menu Opened from the Keyboard

How to Handle Validation Errors When a Form Field Gets Disabled
How to Handle Validation Errors When a Form Field Gets Disabled

How to Build an OTP Input: One Real Input or One per Digit
How to Build an OTP Input: One Real Input or One per Digit