BUILDER

Features

Developers

Documentation

Pricing

Github

Docs

App

This page was made in Builder!

USER GUIDES

Creating Content

Learning the visual editor

Responsive design tricks

Saving layers as templates

Importing your site pages

Connecting custom data

Interactive pages with state and actions

Creating reusable components with Symbols

Targeting and scheduling content

Building custom forms

How To

Sidebar Menu

Dropdown Menu

Platforms

Shopify

Wordpress

Custom

DEVELOPER GUIDES

Guides

Quick start

SEO optimizing Builder.io content

Creating custom models

Using custom fields

Enable on-site previewing and editing

Dynamic URLs and advanced data fetching

Adding Custom Code

Using 3rd party libraries

Import HTML

Extending Builder.io with plugins

REST API

HTML API

Content API

GraphQL API

Webhooks

Write API

React

Getting started

Using Next.js

Using Gatsby

Using your React components in Builder

New!

Components-only mode

Triggering custom actions

Angular

Ruby on rails

Webcomponents

Github

Triggering Customs Actions in Builder with React

Sometimes you want buttons in your builder content to trigger code in your React app. Follow along below to learn how you can do this.

Passing down the function

Using the data attribute, we can pass down any key/value pair we like to be used in our Builder content

export default () => (
  <BuilderComponent 
    name="page" 
    data={{ 
      myFunction: () => alert('Hi!') 
    }} 
  />
)

Triggering the function in builder

Let's assign our function to run on click of a button. Using the data tab, create a new "click" event. In the event handler, there is a state variable that holds all of the data you passed. Simply call state.myFunction() and you are done!

Questions or comments?

Give us a chat, we respond quickly and are here to help!

CHAT US NOW