Skip to main content
t
7d ago

How to change state machine inputs & text runs without hooks

I've been using Rive from @rive-app/react-canvas in my codebase and I've dynamically imported it (deferring the loading of the library function until it is needed), which does not seem to work for the useRive hook so I am only using the default export Rive function. I can render an animation successfully but I am trying to be able to set the state machine input and text runs without being able to import any new hooks. Every time I try to use useRef it doesn't find a defined ref for Rive and/or throws this:
 Warning: Function components cannot be given refs

. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?  

TLDR: Does anyone know how to change state machine inputs & text runs without using useRive or any of the hooks?

1 reply
5d ago

Yes, this is possible. The React runtime should have access to all the vanilla JS functionality, including this:

const inputs = rive.stateMachineInputs(stateMachineName)
const someTrigger = inputs.find((i) => i.name === 'someTrigger')