React runtime for Rive.
@rive-app/canvas
runtime, exposing types, and Rive instance functionality.
Install the dependency
@rive-app/react-canvas
- Wraps the @rive-app/canvas
dependency. Unless you specifically need a WebGL
backing renderer, we recommend you use this dependency when using Rive in your apps for quick and fast usage.@rive-app/react-canvas-lite
- Similar to @rive-app/react-canvas
, but smaller. This is recommended if the Rive graphic does not use Rive Text@rive-app/react-webgl
- Wraps the @rive-app/webgl
dependency. In the future, we may have advanced rendering features that are only supported by using WebGL
. At the moment, however, due to the size of the dependency (with Skia), we do not recommend it unless you have specific needs here. We are currently working on improving the performance and size with the Rive Renderer.@rive-app/react-webgl2
- Wraps the @rive-app/webgl2
dependency. It uses the Rive Renderer with a WebGL2 context and has a much smaller build size than rive-app/react-webgl
. In a future major release, this package may be deprecated, and @rive-app/react-webgl
will make use of the Rive Renderer completely, without an added Skia dependency.WEBGL_shader_pixel_local_storage
Chrome Extension (by adding WebGL Draft Extensions), otherwise, Rive will fall back to an MSAA solution (also with WebGL2) on browsers without the extension support. Current work is underway with major browsers to support this extension by default in consumer’s browsers.Render the Rive component
<Rive />
component.Using the useRive hook
rive
object instance that controls it as well. The Rive object instance allows you to tap into APIs for:useRive
hook returns both this rive
instance, as well as the React component that mounts the underlying <canvas>
element that Rive will draw onto.<RiveCopmonent />
is rendered out, as the underlying <canvas>
element needs to be present in the DOM.className
to RiveComponent
or wrap RiveComponent
with an appropriately sized container.See here for more on the parameters and return values of useRive
.Additionally, explore subsequent runtime pages to learn how to control animation playback, state machines, and more.useRive
to its own wrapper component if you plan on conditionally rendering the <RiveComponent />
returned from the useRive
hook. This is due to Rive being instanced when the component is mounted and the rendering context associated with a specific underlying <canvas>
element. When React tries to unmount/re-render, you may end up with the animation restarting or not displaying when a new <canvas>
is mounted.
By isolating useRive
to its own wrapper component, Rive will have a chance to properly clean up, and restart the animation with a new canvas. In a parent component, you can then conditionally render the wrapper component based on any state or prop-based logic.
Check out this example to see this pattern in use: https://codesandbox.io/s/userive-wrapper-pattern-zx2h3j