Made in Builder.io

Ship Your First Personalized Web Experience webinar on June 15 @ 10AM PT. Register Now

Talk to Us
Product
Developers
Talk to Us

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

Learn how to make your Builder content interactive with state and actions in this 5 minute video.

State is a JavaScript concept that simply says an object is in a certain state, and you can update its properties and its behavior will change accordingly. State and actions make your content interactive. Below, we will show you a simple way to use state and actions.

Start by dragging and dropping in a template. Add two buttons below the template. One button will make the content disappear, and the other will make the content reappear.

Once we have our buttons in place, we are going to use the State object. Click on the reappear button, navigate to the “Data” tab, and click “new action” in the element actions section. Set the action to “click”, and then click “edit action”. This is where we will use a bit of JavaScript. Enter in state.hidden=false; If you’re familiar with JavaScript, you know we can add any property name on the State object. If you aren’t familiar, all you need to know is we are setting State to hidden, and then equaling it to false (while means no). For our other button, we are going to follow the same steps, but state will be set to true: state.hidden=true;

Now you can click on the buttons and see our function working. On the left side of the editor, you can see hidden being toggled on and off when our buttons are clicked. Lastly, we need to bind our hidden property to our content so we can visually see our content disappear/reappear. Click on the content that you want to apply the hidden property to. At the top of the “Data” tab in the binding section, click "get" and select “hide if”. Then, click “from” and select “hidden”.

To learn more about how to add custom code to state bindings or action handlers, check out our Custom Code guide.


Looking to hire a third party to help with your project?

Submit a project request and our partnerships team will reach out to connect you with an Expert from our partner ecosystem.

Connect with us

Was this article helpful?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Get the latest from Builder.io

Developer Newsletter

Latest tips, tricks, and news for frontend developers from our blog

Product Newsletter

Latest features and updates on the Builder.io platform

By submitting, you agree to our Privacy Policy

Product

Features

Pricing

What's New

Resources

Documentation

Blog

Community Forum

Templates

Partners

Submit an Idea

Use Cases

Landing Pages

Headless CMS

Headless Storefront

Customer Showcase

Customer Success Stories

Builder.io logo

Visually build and optimize digital experiences on any tech stack. No coding required, and developer approved.

Get Started

Log In

Product

Features

Pricing

Integrations

Use Cases

© 2023 Builder.io, Inc.

Security

Privacy Policy

SaaS Terms