DEV Community

Cover image for Type Safe, Promise Based, Vue 3 Modals That'll Have You Popping with Joy
Mykolas Mankevicius
Mykolas Mankevicius

Posted on • Edited on

5

Type Safe, Promise Based, Vue 3 Modals That'll Have You Popping with Joy

This post is inspired by promise based modals for React if you want to find out the reasoning, read that post first

Are you tired of overengineering simple things like showing a modal or a dialog? Look no further! I present to you... drumroll... Type Safe, Promise Based, Vue 3 Modals That'll Have You Popping with Joy!

If you're still reading, then you must be interested, or you just like reading long titles. Either way, I've got you covered.

You can see the youtube video below and click the stackblitz link for a short demo. But if you really want to experience the actual Dev UX of using this, then download and run this in VSCode.

In the past, I overengineered modals like a mad scientist, but after attending a Vilnius.js meetup and seeing a talk by Gediminas Ubartas on how they implemented modals in their company, I decided to simplify my approach.

The result? Simply amazing. TypeSafe, Promise Based, Modals/Dialogs simply by providing a component to the showModal function in the useModalsProvider.ts file. Plus, the types ensure that you'll never have to worry about runtime errors again. Return types from the showModal show you what to expect. The props argument makes sure that you provide everything the Modal Component requires to work!

Image description

But that's not all, folks! There are extra things you can add to improve Client Side UX. I've done these extra things in my codebase, but they are very much based on what you prefer and how you prefer to do it. If you want to see these in a post, let me know in the comments.

So there you have it. Type Safe, Promise Based, Vue 3 Modals That'll Have You Popping with Joy! Don't take my word for it, try it out for yourself. And remember, always keep it simple, my friend.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more