Medium
5 MIN

Understanding Custom States in Bubble.io (Easy Version)

Learn how to exploit the full potential of Custom States in Bubble.io, in order to create dynamic and optimized applications without having to manipulate the database.
Illustration Blog Emvpee - Custom States Bubble.io
Clement Ballion, expert Bubble.io & No code
Clément Ballion
Emvpee Founder & Bubble.io Expert.
Logo LinkedinPhone iconeMail icone
Syamak Azadeh, expert Bubble.io & No code
Syamak Azadeh
Engineer & Bubble.io Specialist.
Logo LinkedinPhone iconeMail icone

What are Custom States in Bubble.io?

Custom States are one of the most powerful concepts but often misunderstood in Bubble.io. Unlike data stored in databases, Custom States are temporary variables that exist only in the browser of the user during their active session. They are a fundamental pillar for creating interactive and responsive applications without having to constantly manipulate the database.

In this article, we are going to explore the Custom States in depth, locate them with specific use cases and understand how they can improve the user experience and optimize the performance of your Bubble.io applications.

Why use custom states?

Custom States offer several advantages compared to traditional database storage:

  1. Speed of execution : Custom State operations are instantaneous because they run on the client side, without communication with the server
  2. Resource saving : They reduce server load and WU (Workload Units) consumption
  3. Temporary data : Great for storing information that doesn't need to be permanent
  4. Dynamic manipulation : Ideal for real-time interface changes

🔑 Key concept : Think of Custom States as a temporary whiteboard where you jot down information as you work, but delete it when the task is complete. They disappear when the page is refreshed!

Custom States vs. Database: What's the difference?

Before we go any further, let's clarify the fundamental distinction between changes in Custom States and in the database in Bubble:

← Scroll horizontally →
Custom States Database
Persistance Temporairy (User session) Permanent
Visibility Connected User only All Users (accordingly to Privacy Rules)
Speed Lightning fast (Client side) Slower (Server side)
WU Consumption No Yes
Ideal for Temporary data, dynamic UI Permanent data, to stay
Survives page refresh No Yes

The different types of Custom States in Bubble

Bubble allows you to create several types of Custom States :

  1. Text : To store character strings
  2. Number : For numerical values
  3. Yes/No : For boolean values
  4. Date : To store dates and times
  5. List of... : To store collections of items
  6. Purpose : To store complex data structures

EMVPEE Banner

Need help for your App?

We help you understanding Custom States.

  • Types of use
  • Best practices
  • Performances optimisation

How to create and manipulate Custom States

Creating a Custom State

To create a Custom State in Bubble.io, it's very simple. For this example, we're going to apply it to a button.

  1. Select the element on which you want to create the Custom State (the button)
  2. Go to the” Custom States“ tab in the properties panel
  3. Click on”Add a new state
  4. Name your state (use a clear naming convention)
  5. Choose the type of data
  6. Define a initial value if required

Capture création Custom State Bubble.io
Custom State Bubble.io creation capture

💡 Tip : Adopt a consistent naming convention for your Custom States. For example, prefix them with “cs” or “state” to easily distinguish them from database fields in your workflows.

Apply a custom state

To change a Custom State, use the “Set state” action in your workflow:

  1. Create a Workflow (at the click of the button)
  2. Add the action ”Set state
  3. Select your element and the state to be modified
  4. Define the new value
  5. Don't forget to pass the State back to its initial value

3 practical custom state use cases

1. Multi-step forms

Multi-step forms are one of the most common use cases for custom states.

Concrete example :

  • Create a custom stateStep Form“ (type: number) with an initial value of 1
  • Create multiple groups corresponding to each step of the form
  • Condition the display of each group according to the value of the state
  • Use buttons ”following“and”Previous“ to change the State value

⚠️ Important note : The idea here is to store the data entered in Custom States throughout the process and then save it to the database only at the last stage. This prevents unnecessary server calls, WU consumption, and improves the user experience.

2. Shopping carts

Custom States are perfect for managing a shopping cart before finalizing an order.

Concrete example :

  • Create a Custom StateShopping Cart Items“ (type: List of products)
  • Add an actionAdd to list“ on the button ”Add to basket
  • View the contents of the basket and calculate the total dynamically
  • Save to the database only when final validation

💡 Practical tip : To manage quantities, you can either add the same product to the list several times, or create an object-type Custom State that stores the product and its quantity.

3. Conditional user interface

Adapt the appearance and the behavior of your interface based on user actions.

Concrete example : Quickly switch between 2 interfaces

  • Build your 2 interfaces on your page, group them into a group ”Interfaces_group
  • Create a Option Set: ”Interface type“ with the 2 types of interfaces (Let's say ”Interface 1“ and ”Interface 2“)
  • Create a Custom State on the band interfaces - Name= ”Interface“ (type: Set Option created)
  • Create a Repeating Group which displays the fields of the Option sets (”Interface 1“ and ”Interface 2“)
  • Create a workflow by clicking on the texts in the Repeating group: When text is clicked > Set state of “Groupe_interfaces” > Current Cell “Interface Type”
  • Create conditional values on each of your interfaces for Show or hide depending on the type of interface that is chosen (+ Collapse When Hidden).

🔥 Discover our Tips & Tutorial on the subject: How to swap between interfaces with a Custom State

Optimizing performance with Custom States

The strategic use of Custom States can dramatically improve the performance of your Bubble.io application:

  1. Reducing server calls : By temporarily storing data on the client side, you reduce the number of interactions with the server
  2. Economy of WU : Custom State manipulations do not consume Workload Units, unlike database operations
  3. Increased responsiveness : Interface changes based on Custom States are instant

💡 Insight performance : On a complex multi-stage form, using Custom States to store intermediate data can reduce WU consumption by up to 80% compared to backing up at each stage!

Common mistakes and how to avoid them

1. Forget that Custom States are temporary

🔴 Problem : Data loss when the page is refreshed.

Solution : Use the localStorage (via the plugin of the same name) or the database for data that must persist.

2. Creating too many Custom States

🔴 Problem : Code becomes difficult to maintain and debug.

Solution : Use objects to group related states (ex: a “filter” object rather than several separate states).

3. Confusion between page states and group states

🔴 Problem : Unreachable states or unexpected behavior.

Solution : Create the states at the appropriate level and use the correct reference (this page vs parent group vs element).

4. Do not initialize Custom States

🔴 Problem : JavaScript errors when trying to access an uninitialized state.

Solution : Always set an appropriate default value.

Conclusion

💙 The final word : Custom States are one of Bubble.io's most powerful tools for creating dynamic and efficient applications. By mastering their use, you can considerably improve the user experience and optimize the performance of your applications. Feel free to experiment with different approaches and to combine Custom States with other Bubble features to create rich and complex interactions!

EMVPEE Banner

A project in mind?

We help you develop your Bubble.io application within 4 weeks.

  • 100% Customized design
  • API Integrations
  • Performances optimisation
  • Training & Videos

Our latest blog posts on Bubble.io

Read our latest articles on Bubble and don't miss out on the next ones!

All the items