all articles

How to reuse components with Reusable elements and Popups | Bubble

Andrii Bas
Founder & CEO
How to reuse components with Reusable elements and Popups | Bubble
Create 10x faster with Sommo
✓ 10+ years of experience
✓ 120+ products developed
✓ no-code&code expertise
✓ in-house development
contact us
Create mobile app with Natively
✓ automated conversion
✓ for any website/web app
✓ mobile native features
✓ updates without release
try Natively

When building your app on Bubble, it's a common use-case to have some data record that you need to display in different places.

Let's take the user profile as an example, which has fields like the first name, second name, email, phone, address, etc. A typical app might need to display this profile info on the following screens:

  1. My profile section (for users to view/edit their own profile).
  2. User profile (public or admin-only view).
  3. Add user screen/popup.
  4. Edit user screen/popup.

An obvious (ineffective) solution would be just to copy-paste these UI elements and workflows, customizing them where needed.

Even though it will work, there will be a lot of repeating elements and workflow; such an app will be tremendously hard to maintain/update and prone to errors and inconsistencies.

This article will show how to use powerful Bubble features such as reusable elements and passing data to the popups. And you'll cover all 4 of the use cases above with just one component!

How to reuse components with Reusable elements and Popups | Bubble - 1

App setup and data

To demonstrate what we're building, we've created a simple app example here that you can test here. The app has a few simple screens:

  1. Landing
  2. Login / Signup
  3. Home screen
  4. My profile
  5. Users (Admin-only view)

The app has just one (default) data type — "User" with a few typical fields.


Reusable element "User profile view"

Let's start by creating a reusable element, "User profile view" (Bubble docs). Its type of element should be "Group", and the type of content — "User". This is important since we'll be able to pass the data of this type to this group only if the type of content is set.

How to reuse components with Reusable elements and Popups | Bubble 2


For the click on the "Save" button, we'll just add a workflow action "Make changes to a thing", and save all the input fields to the respective fields of the User model.

How to reuse components with Reusable elements and Popups | Bubble 3

My profile screen

Now, let's create a "My profile" screen, in which we'll place our reusable element "User profile view" (at the bottom of the left menu), and pass "Current user" as the "Data source".

How to reuse components with Reusable elements and Popups | Bubble 4

And that's it; we already reused our element.


User profile

Let's also create a User profile screen (with the type of content "User"), where we'll display the information of a specific user. Such screens can be public or admin-only. In our case, it's an admin-only screen, so all the details should also be editable.


As a data source, we'll pass "Curren Page User".

How to reuse components with Reusable elements and Popups | Bubble 5


As an extra button, we'll add "Delete user" button and extend our reusable element with the dropdown that would change the user's status. We'll also "auto-bind" it to the user's "status" field.


Congratulations, we've re-used the element again!


Add/Edit user popup

Let's create an admin-only screen "Users", where admins can search/view users and change their status or details.

How to reuse components with Reusable elements and Popups | Bubble 6

We'll also want to have a quick way to open the "Edit user" popup right there from the list, to save time for admins making changes to the users.


To implement it, let's create a new reusable element, this time of the type of element "Popup", and the type of data — "User". At the center of the popup we'll put the same "User profile view" element and pass "Parent group's User" as a data source to it.

How to reuse components with Reusable elements and Popups | Bubble 7


However, we'd need to handle two use-cases here:

  1. Add user (all fields are empty) with the "Add" button.
  2. Edit user (fields with the user data) with the "Save" button.


To handle these 2 cases, we'll need to add a couple of conditions and compare if "Parent group's User is not empty". If it's empty, we'll change the title and the button to "Add user" and "Add" respectively.


We'll add a condition to check if the parent group's user is empty on the click on the button. If it's empty, we'll perform the action "Create an account for someone else", and save all the respective fields for the user.

How to reuse components with Reusable elements and Popups | Bubble 8

* Note: usually, you'll use the "Create a new thing" action here. But because the "User" data type is special in Bubble, we need to use a particular action to create this data type.


Then we'll add the workflow on the "Edit" button to "Display data in Add/Edit user popup", and then "Show" this popup (for "Add" button — to reset the data and show this popup).



How to reuse components with Reusable elements and Popups | Bubble 9


You can customize the view according to different conditions (like user status, currently logged-in user role, page, etc.), to match your unique app requirements.


Summary

By using Bubbles features such as reusable group and passing data to popups we could reuse the same component in 4 different places, thus significantly reducing the need to duplicate the code and workflows.


Check out this video to view the detailed walkthrough of the app and all the features:


The link to the test app: https://popup-edit-records-demo.bubbleapps.io/version-test/

Admin credentials: andriy.bas+1@uptech.team / qwerty


If you need any help building functional apps with great UX and UI on no-code, don't hesitate to contact us.

Andrii Bas
Founder & CEO

Related posts

How to embed Youtube videos in Bubble apps

In this article, we’ll dive into 3 use-cases: embed a single video; embed a video by Video ID; parse the URL and embed the video. Plus, we’ll share a few tips and tricks on how to work with embedded videos in the list.‍

bubble
tech talks
how-to
youtube

How to embed Youtube videos in Bubble apps

6 Benefits Of Mobile Apps For Businesses

In this article, we'll show you how mobile apps compare against websites and why users are likelier to use an app to engage with your business.

mobile development
enterprise

6 Benefits Of Mobile Apps For Businesses

Have an idea?
Let’s build your app 10x faster!

CONTACT US
Sommo development agency on ProductHunt
We are live on
!
Your support will help us a lot!
Get a fast project estimate
Book a call with our CEO, Andrii Bas, and our Head of Business Development, Vadym Erhard, for a fast, realistic project estimate and insights on low-code development.