Bridging Weweb and Javascript Variables in under 15 minutes

9 Jun 2023 · 15 min
14:31

In this tutorial Ray Deck walks through how to connect external JavaScript code to WeWeb’s state management system. He starts by creating a text variable (headerInfo) in WeWeb, binding it to a heading, and adding a button workflow that updates the variable when clicked. He then attempts to manipulate the variable from a custom script tag, encountering errors because the variable isn’t a global JavaScript variable. By enabling the “Show Dev Information” panel, he copies the internal variable ID and discovers the global `dublib` object that WeWeb injects. Using `dublib.variable.getValue` and `dublib.variable.updateValue` with the copied ID, he demonstrates reading and writing the WeWeb variable from any JavaScript context. He builds a timer with `setInterval` that calculates elapsed time, formats minutes, seconds, and milliseconds, and pushes the formatted string back into the WeWeb variable each second, causing the bound heading to update in real time. Throughout, he shows debugging steps in DevTools, explains common pitfalls (e.g., typos, missing IDs), and encourages viewers to explore deeper integrations via StateChange.ai’s community and office hours.

Chapters

More from Ray

youtube.com

Be the Looker

7mo ago
youtube.com

Operators Optimize, Innovators Integrate

7mo ago
youtube.com

Move Over Vibe Coding

7mo ago
youtube.com

Two Customer Challenges

7mo ago
youtube.com

Trust is a Competitive Moat

7mo ago
youtube.com

Be Verbose With Your Errors

7mo ago
youtube.com

Build for AI, Not Just With It

7mo ago
youtube.com

A Technology Business

7mo ago
youtube.com

Interdimensional Studying

7mo ago
youtube.com

Interdimensional Learning

7mo ago
youtube.com

Gain True Mastery

7mo ago
See all content