Skip to main content
DEPRECATION NOTICE: This entire page documents the legacy Events system. For new projects: Use Data Binding instead. For existing projects: Plan to migrate from Events to Data Binding as soon as possible. This content is provided for legacy support only.
With Rive events, you have the ability to subscribe to meaningful signals that get reported from animations, state machines, and Rive listeners, all created at design time from the Rive editor. These signals can be subscribed to at runtime and have a specific name, type, and various custom metadata that may accompany the event to help inform the context surrounding its meaning. For more on the Events feature in general, check out the Events page in the editor section of the docs. The Event system has also been expanded to support Audio Events to trigger audio to play in the editor and at runtime. For example, in a Rive graphic simulating a loader, there may be an event named LoadComplete fired when transitioning from a complete timeline animation state to an idle state. You can subscribe to Rive events with a callback that the runtime may invoke, and from there, your callback can handle extra functionality at just the right moment when the event fired. Other practical use cases for events:
  • Coordinating audio playback at specific moments in an animation, see Audio Events
  • Opening a URL when specific interactions have occurred
  • Adding haptic feedback on meaningful touch interactions
  • Implementing functionality on Buttons and other UI elements
  • Send semantic information
  • Communicate any information your runtime needs at the right moment

Subscribing to Events

When you subscribe to Rive events at runtime, you subscribe to all Rive events that may be emitted from a state machine, and you can parse through each event by name or type to execute conditional logic. Let’s use a 5-star rater Rive example to set any text supplied with events and open a URL if one is given.

Examples

Adding an Event Listener

Similar to the addEventListener() / removeEventListener() API for DOM elements, you’ll use the Rive instance’s on() / off() API to subscribe to Rive events from the rive object returned from the useRive hook. Simply supply the RiveEvent enum and a callback for the runtime to call at the appropriate moment any Rive event gets detected.
Note: You must use the useRive() hook to subscribe to Rive events

Example Usage

import { useRive, EventType, RiveEventType } from '@rive-app/canvas';
import { useCallback, useEffect } from 'react';

const MyTextComponent = () => {
const {rive, RiveComponent} = useRive({
    src: "/static-assets/star-rating.riv",
    artboard: "my-artboard-name",
    autoplay: true,
    // automaticallyHandleEvents: true, // Automatically handle OpenUrl events
    stateMachines: "State Machine 1",
});

const onRiveEventReceived = (riveEvent) => {
    const eventData = riveEvent.data;
    const eventProperties = eventData.properties;
    if (eventData.type === RiveEventType.General) {
    console.log("Event name", eventData.name);
    // Added relevant metadata from the event
    console.log("Rating", eventProperties.rating);
    console.log("Message", eventProperties.message);
    } else if (eventData.type === RiveEventType.OpenUrl) {
    console.log("Event name", eventData.name);
    // Handle OpenUrl event manually
    window.location.href = data.url;
    }
};

// Wait until the rive object is instantiated before adding the Rive
// event listener
useEffect(() => {
    if (rive) {
    rive.on(EventType.RiveEvent, onRiveEventReceived);
    }
}, [rive]);

return (
    <RiveComponent />
);
};

Additional Resources