ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Follow publication

Member-only story

Managing modals in React

This is a simple guide to some approaches that i’ve seen taken to managing modals in React applications and components

Evan Burbidge
ITNEXT
Published in
5 min readJan 16, 2023

--

Introduction

Websites use modals to enhance the user experience. Modals provide an effective way to present information and can be used to draw attention to key elements on a page. They can provide a user with a quick overview of a page’s content and can also be used to present options to the user. Modals can also be used to alert a user of an action or event that needs to be taken in order to complete a task. By using modals, websites can create a more interactive and engaging experience for their users.

Throughout this article, we will look at some of the ways that we can manage multiple modals within our application.

The typed approach

This approach is likely the most straightforward way to use modals, but it does require you to use Typescript in your codebase. We can employ a single state variable with a predefined type to control the modals on our page. The main benefits are that no unnecessary modals will be present, and we can easily identify which modals are active.

type MODALS = "CLOSED" | "CREATE_MODAL" |…

--

--

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Written by Evan Burbidge

Javascript developer specialising in React, Vue and NodeJS. I like SQL and NoSql depends on the context really!

Responses (3)

Write a response