Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Script

The Script component can be used to include inline javascript or javascript files by URL.

It uses the next/script component to inject the script and can be safely used with conditional rendering to allow script side effects to be controlled by the state.

Complex inline scripting should be avoided. If the code to be included is more than a couple lines, it is more maintainable to implement it in a separate javascript file in the assets directory and include it via the src prop.

This component is particularly helpful for including tracking and social scripts. Any additional attrs needed for the script tag can be supplied via custom_attrs prop.

This code renders to something like the following to enable stat counting with a third party service.

API Reference

rx.script

Next.js script component.

PropType | ValuesDefault
src
str
strategy
"afterInteractive" | "beforeInteractive" | ...
( LiteralVar.create("afterInteractive") )

Event Triggers

See the full list of default event triggers
TriggerDescription
on_load Triggered when the script is loading
on_ready Triggered when the script has loaded
on_error Triggered when the script has errored