
Vidushi Saxena
Developer
Category: Engineering

Vidushi Saxena
Developer
A configurable React animation component needs more than a tidy prop interface. It needs a resolution model: which preset supplies the baseline, which overrides consumers may change, which user or device constraints take priority, and which runtime states belong to the animation itself.
Vault already has a broader guide to building reusable React animation components without making every effect config-heavy. That article deals with public API design, prop explosion, composition, shared motion rules, and when source edits are more appropriate than more configuration.
This article starts one layer deeper: how should a visual effect resolve presets, bounded overrides, environment constraints, and runtime behavior without leaking renderer internals into its public API?
We will use a generic ParticleField architecture throughout. The code is an implementation skeleton for the configuration and lifecycle layers; the renderer itself is intentionally left separate because a DOM, Canvas, and WebGL renderer would need different production logic.
The example has three art-direction presets-ambient, energetic, and minimal-while keeping one renderer contract. The goal is to make configuration precedence explicit and expose the point where another “variant” should stop being a preset and become a different component.
Start with one invariant and three kinds of change
“Variant” is too vague to carry an architecture.
In a design review, variant might mean the quieter version of a background. In Motion, variants are named animation targets such as hidden and visible. In a component library, a variant may describe appearance. A touch fallback may also get called a variant in conversation.
Those are different kinds of change.
| Layer | Question | ParticleField example |
|---|---|---|
| Structure | What makes this the same component? | Same renderer family, semantics, and lifecycle contract |
| Preset | Which coherent visual treatment was selected? | ambient, energetic, minimal |
| Override | Which narrow values may a caller tune? | intensity |
| Runtime state | What is happening now? | idle, active, entering, leaving |
Structure is the invariant that makes multiple presets worth keeping in one component. Presets and overrides are configuration, while runtime state belongs to behavior and changes while the component is alive.

That matters when using libraries such as Motion. Motion's variants are reusable named animation targets and orchestration primitives. They are useful for states such as idle, active, or visible, but they do not need to mirror application-level visual presets such as ambient or energetic.
A preset may alter parameters inside an existing renderer contract. It should not quietly replace that contract. If energetic suddenly needs a different renderer, dependency family, event model, and cleanup path, the useful abstraction may already have split.
Give configuration an explicit order of precedence
The difficult part is deciding what wins when inputs disagree.
Suppose design selects energetic. The page sets intensity={0.8}. The user prefers reduced motion. The device's primary pointer is coarse, so pointer-following behavior may be inappropriate.
The component needs an answer before those conditions are distributed across JSX and Effects.
Preset baseline ↓Allowed developer overrides ↓User + input capability constraints ↓Resolved renderer configuration ↓Runtime interaction stateThe preset establishes coherent art direction. A narrow override surface allows documented page-level tuning. Environment policy then gets final authority over the resolved behavior, so a developer override cannot accidentally restore motion that reduced-motion handling intentionally removed.
Only then does the animation enter runtime state. This order is the contract every later layer must preserve.
Build a typed preset registry
Start with the stable values the renderer will eventually consume.
For this example:
densityis a non-negative illustrative particle count.speedis a normalized implementation value, not pixels per second.opacityis normalized from0to1.spreadis a normalized distribution value from0to1.interactionModechooses the interaction strategy available to the renderer.
type ParticlePreset = | "ambient" | "energetic" | "minimal" type InteractionMode = | "drift" | "pointer" | "static" type ParticleConfig = { density: number speed: number opacity: number spread: number interactionMode: InteractionMode} const particlePresets: Record< ParticlePreset, ParticleConfig> = { ambient: { density: 44, speed: 0.35, opacity: 0.42, spread: 0.72, interactionMode: "drift", }, energetic: { density: 88, speed: 0.85, opacity: 0.72, spread: 1, interactionMode: "pointer", }, minimal: { density: 22, speed: 0.2, opacity: 0.28, spread: 0.5, interactionMode: "drift", },}These values are illustrative, not a Vault API.
The registry keeps a preset coherent. energetic is defined in one place instead of becoming a collection of preset === "energetic" branches scattered across JSX, hooks, and styles. The naming also matters. interactionMode is more precise than behavior, because behavior will later describe runtime state.
Make overrides narrow, bounded, and cheap to disable
Now expose one allowed override:
type ParticleFieldProps = { preset?: ParticlePreset intensity?: number className?: string}number alone is not a useful contract, so define intensity as attenuation from 0 to 1:
0disables the animated treatment.1uses the preset at its authored strength.- values outside that range are clamped;
- non-finite values fall back to
1; - the override cannot amplify a preset beyond its authored maximum.
function clampUnit(value: number) { if (!Number.isFinite(value)) return 1 return Math.max(0, Math.min(1, value))} function applyIntensity( config: ParticleConfig, intensity: number,): ParticleConfig { const safeIntensity = clampUnit(intensity) if (safeIntensity === 0) { return { ...config, speed: 0, opacity: 0, interactionMode: "static", } } return { ...config, speed: config.speed * safeIntensity, opacity: clampUnit( config.opacity * safeIntensity, ), }}The 0 case is important. Lowering opacity to zero while leaving pointer listeners or frame work active would suppress the visual result without suppressing its runtime cost.
This resolver only establishes the policy. The renderer must still respect interactionMode: "static" and avoid unnecessary work.
Another component might use a different intensity contract-perhaps a bounded multiplier around 1, or named values such as subtle | normal | strong. What matters is that the meaning, bounds, and precedence are explicit.
Resolve environment policy after developer overrides
With preset and override resolved, environment constraints come next.
For this example:
- reduced motion selects a static treatment;
- a coarse primary pointer disables pointer-following mode;
- the coarse-pointer fallback uses gentle drift rather than pointer response;
- reduced motion still outranks that fallback and removes continuous movement.
type Environment = { reducedMotion: boolean coarsePointer: boolean} function applyEnvironment( config: ParticleConfig, environment: Environment,): ParticleConfig { let next = { ...config } if ( environment.coarsePointer && next.interactionMode === "pointer" ) { next.interactionMode = "drift" } if (environment.reducedMotion) { next = { ...next, speed: 0, interactionMode: "static", } } return next} function resolveParticleConfig({ preset, intensity, environment,}: { preset: ParticlePreset intensity: number environment: Environment}) { const base = particlePresets[preset] const withOverride = applyIntensity( base, intensity, ) return applyEnvironment( withOverride, environment, )}Using drift as the coarse-pointer fallback is an editorial choice for this example, not an accessibility guarantee. Another interaction may be better served by a static treatment, touch-specific behavior, or no effect at all.
Likewise, (pointer: coarse) generally describes the primary pointing device. Hybrid hardware can expose several input methods, so it should not be treated as a universal “this device is touch-only” test.
Reduced motion deserves separate treatment because it expresses a user preference about non-essential motion. Motion exposes useReducedMotion() for adapting React animation logic, while the platform also exposes the preference through prefers-reduced-motion.
Because this example is purely decorative, the visual container can be hidden from assistive technology. Meaningful content must remain outside it.
aria-hidden="true"That is more precise than treating reduced motion as the entire accessibility strategy. Keyboard operation, focus, semantics, readable content, and input independence still matter wherever an effect interacts with real UI.
Keep capability detection outside the preset
Authored presets should not know what browser or input environment they happen to be running in.
A small hook can provide the coarse-primary-pointer signal:
"use client" import { useEffect, useState,} from "react" function useCoarsePointer() { const [coarse, setCoarse] = useState(false) useEffect(() => { const query = window.matchMedia( "(pointer: coarse)", ) const update = () => { setCoarse(query.matches) } update() query.addEventListener( "change", update, ) return () => { query.removeEventListener( "change", update, ) } }, []) return coarse}React's useEffect documentation frames Effects as synchronization with external systems such as browser APIs, subscriptions, timers, and third-party animation libraries. The same lifecycle should own setup and cleanup.

Because this hook starts with false and reads the media query after mount, a coarse-pointer environment may briefly resolve the non-coarse path before the Effect updates state. That is acceptable for this architectural example, but production code should verify the initial transition in its actual rendering context rather than assume it is synchronous or invisible.
The broader rule remains useful: if a component starts listeners, observers, timelines, or animation frames, it should also know how to stop them.
Give runtime interaction its own lifecycle
Once configuration has selected the interaction mode, the runtime layer can implement it without rediscovering presets.
This example tracks pointer position relative to the viewport, which makes sense for a page-wide decorative field. A component-local effect would normally calculate position from the element's bounds instead.
import { type RefObject, useEffect,} from "react" function useParticleBehavior( ref: RefObject<HTMLDivElement | null>, interactionMode: InteractionMode,) { useEffect(() => { if ( interactionMode !== "pointer" ) { return } const element = ref.current if (!element) return let frame = 0 const onPointerMove = ( event: PointerEvent, ) => { cancelAnimationFrame(frame) frame = requestAnimationFrame(() => { const x = event.clientX / window.innerWidth const y = event.clientY / window.innerHeight const offsetX = (x - 0.5) * 12 const offsetY = (y - 0.5) * 12 element.style.setProperty( "--pointer-offset-x", `${offsetX}px`, ) element.style.setProperty( "--pointer-offset-y", `${offsetY}px`, ) }) } window.addEventListener( "pointermove", onPointerMove, { passive: true }, ) return () => { window.removeEventListener( "pointermove", onPointerMove, ) cancelAnimationFrame(frame) } }, [interactionMode, ref])}The hook depends on the primitive that changes its lifecycle: interactionMode. It does not receive the whole configuration object simply because that object exists.
The renderer would consume those offsets to update its visual response. If the same element receives the custom properties and the transform, the relationship is direct:
.particle-field { transform: translate3d( var(--pointer-offset-x, 0px), var(--pointer-offset-y, 0px), 0 );}If the custom properties are set on a wrapper and consumed by a descendant, that relationship should be intentional and rely on custom-property inheritance rather than happen accidentally.
A Canvas or WebGL renderer would consume equivalent pointer values differently and would need its own rendering and cleanup logic. That difference is exactly why the behavior contract and renderer contract should remain visible.
Preset and Motion state are separate axes
If Motion is the animation engine, product-level preset and runtime animation state still solve different problems.
A simplified example can derive Motion targets from the already resolved configuration:
import { motion } from "motion/react" function MotionField({ config, isActive,}: { config: ParticleConfig isActive: boolean}) { const idleOpacity = config.opacity * 0.75 return ( <motion.div initial={{ opacity: idleOpacity, }} animate={{ opacity: isActive ? config.opacity : idleOpacity, }} /> )}The preset decides the baseline config.opacity. Runtime state decides whether the component is currently at its idle or active target.
Motion's animation variants can still be useful when several elements need named states or orchestration. The point is to avoid making visual-preset terminology and runtime-state terminology accidentally interchangeable.
Connect the layers with an integration skeleton
At this point the component can connect configuration and lifecycle responsibilities:
"use client" import { useRef,} from "react" import { useReducedMotion,} from "motion/react" export function ParticleField({ preset = "ambient", intensity = 1, className,}: ParticleFieldProps) { const rootRef = useRef<HTMLDivElement>(null) const reducedMotion = useReducedMotion() const coarsePointer = useCoarsePointer() const config = resolveParticleConfig({ preset, intensity, environment: { reducedMotion: Boolean(reducedMotion), coarsePointer, }, }) useParticleBehavior( rootRef, config.interactionMode, ) return ( <ParticleRenderer ref={rootRef} config={config} className={className} /> )}This is an integration skeleton, not a complete particle implementation.
ParticleRenderer is intentionally omitted because its responsibilities depend on the chosen renderer. A DOM renderer might create positioned elements. Canvas would need drawing and resize logic. WebGL could introduce shaders, textures, DPR handling, resource disposal, and a continuous frame loop.
The contract it must satisfy is small:
type ParticleRendererProps = { config: ParticleConfig className?: string}If it accepts the ref shown above, it must be implemented as a ref-capable component using the appropriate React ref pattern for the project's React version.
The renderer should consume:
density;speed;opacity;spread;interactionMode;- pointer offsets when pointer interaction is enabled.
It should also treat interactionMode: "static" as an instruction to avoid unnecessary interactive or continuous work where its rendering model allows that.
The visual proof should use the same renderer three times
The production asset for this article should render the same implementation at the same dimensions:
<ParticleField preset="ambient" /> <ParticleField preset="energetic" /> <ParticleField preset="minimal" />
The comparison should demonstrate controlled variation rather than three unrelated pieces of particle artwork.
| Preset | Intended difference | Must remain stable |
|---|---|---|
| ambient | Lower density and gentler movement | Renderer, semantics, lifecycle model |
| energetic | Higher density and pointer response where appropriate | Renderer, configuration pipeline |
| minimal | Quieter visual presence | Renderer, fallback policy |
A second capture can show energetic with reduced motion enabled. That is more useful than another decorative variation because it demonstrates precedence: the visual treatment stays recognizable while the environment policy changes how it moves.
Know when the renderer contract has broken
A preset works when the variation remains inside an existing technical contract.
| Requested change | Recommended approach |
|---|---|
| Lower opacity | Preset / Override |
| Fewer particles | Preset / Override |
| Stronger authored treatment | Preset / Override |
| Pointer response within same renderer | Preset / Override (sometimes) |
| Different semantic content | Separate Component |
| DOM becomes Canvas | Separate Component |
| CSS treatment becomes shader scene | Separate Component |
| Passive decoration becomes draggable UI | Separate Component |
| New dependency and lifecycle family | Separate Component |
Consider two visual treatments both described as “glass.”
One is CSS blur and gradients. The other is a refractive WebGL scene using textures, shaders, resize logic, DPR decisions, a frame loop, and graphics-resource cleanup.
A public API like this is short:
<Glass variant="css" /><Glass variant="webgl" />But it hides two substantially different rendering contracts.
When a visual treatment requires a distinct renderer, dependency family, or lifecycle model, a separate component is usually clearer than preserving one component name at any cost.
Vault's dependency documentation follows the same broad production principle at the collection level: different effects can require different technical engines rather than every interaction inheriting one universal runtime.
In Next.js, keep the browser boundary narrow
A page does not need to become a Client Component merely because it contains one animated layer.
// app/page.tsximport { HeroEffect } from "./hero-effect" export default function Page() { return ( <main> <section className="hero"> <div> <h1> Build interaction with intent. </h1> <p> Static content stays outside the visual effect. </p> </div> <HeroEffect /> </section> </main> )}// app/hero-effect.tsx"use client" import { ParticleField,} from "./particle-field" export function HeroEffect() { return ( <ParticleField preset="ambient" intensity={0.8} /> )}Next.js documents this composition model in its Server and Client Components guidance. Browser-dependent interaction belongs behind a client boundary, while surrounding static content can remain server-rendered.
Named configuration works well at that boundary because values such as "ambient" and 0.8 are plain serializable inputs. Engine instances, callbacks tied to browser state, and imperative animation objects belong on the client side.
The initial render should also avoid unguarded browser values, random output, or client measurements that would make the server and client disagree about the initial structure.
Production acceptance criteria
TypeScript correctness is only the beginning. A configurable effect should have observable acceptance criteria.
| Area | Acceptance criterion |
|---|---|
| Preset resolution | Every preset resolves deterministically |
| Override bounds | Invalid, negative, excessive, and non-finite inputs stay inside policy |
| Intensity zero | Visual output is suppressed and avoidable interactive work is disabled |
| Precedence | Environment policy wins where documented |
| Reduced motion | Motion is actually reduced or removed |
| Coarse pointer | Pointer-following behavior has a deliberate fallback |
| Hybrid input | Primary-pointer detection is not treated as universal device classification |
| Semantics | Removing the effect does not remove meaning |
| Keyboard | Required UI remains operable independently of decorative motion |
| Hydration | Initial markup does not depend on unstable browser-only values |
| Cleanup | Listeners, observers, frames, timelines, and renderer resources stop correctly |
| Resize | Measurements and render surfaces update without stale state |
| Offscreen state | Continuous work pauses where the renderer is expected to support that |
| Canvas/WebGL | DPR, resources, frame loops, and disposal are explicitly handled |
| Visual regression | Presets are reviewed at identical dimensions |
| Production build | Behavior is tested in the actual build being shipped |
These are acceptance targets for the eventual implementation, not claims that the abbreviated renderer skeleton already satisfies every row.
A DOM effect, Canvas renderer, text reveal, and WebGL scene do not carry the same cost profile. The architecture should expose those differences instead of smoothing them into a generic “animation component.”
Optimize the system doing the expensive work
In this example, the small preset resolver is unlikely to dominate runtime cost.
React rendering can matter, but so can DOM volume, repeated layout measurement, scroll work, DPR, shader complexity, textures, asset decoding, and continuous rendering that remains active when the scene is no longer useful.
React describes memoization APIs as performance tools rather than semantic requirements. A clean configuration architecture should therefore work without depending on useMemo for correctness.
Profile the layer doing the work. If React reconciliation is expensive, inspect React. If the frame loop is expensive, inspect the frame loop. If WebGL is expensive, inspect resolution, shader work, textures, draw calls, and whether continuous rendering is necessary.
Configuration architecture improves reasoning. It does not replace profiling.
Source-first effects make these boundaries inspectable
This architecture becomes more useful when teams can inspect and change the implementation rather than only configure a sealed external interface.
At Hyperiux Vault, we take a source-first approach to our effects, scoping dependencies to each individual interaction rather than requiring a single engine across the entire collection. See our Vault dependency documentation for more details.
That does not mean every Vault effect follows the ParticleField model in this article, nor does editable source imply unrestricted redistribution. Usage rights still follow the applicable Vault licence.
The practical value is implementation ownership. A team can inspect where configuration resolves, remove controls it does not need, align the effect with its existing design system, tighten a Next.js client boundary, or split a renderer when one visual treatment has outgrown the original architecture.
Source access does not make architectural decisions disappear. It makes them editable.
A practical decision flow
The architecture becomes clearer when classification and validation are treated as two separate phases.
Phase 1: classify the variation
Does the renderer, semantic role,and lifecycle contract stay the same?│├─ No│ → Consider a separate component.│└─ Yes ↓Is this a recurring coherent visual treatment?│├─ Yes│ → Represent it as a preset.│└─ No ↓Is this a legitimate caller-level tuning need?│├─ Yes│ → Expose a bounded override.│└─ No → Keep it internal.Whichever configuration path is chosen, the effect still moves through the same production resolution stage.
Phase 2: resolve and validate the effect
Preset / override / internal configuration ↓Apply user and device constraints ↓Resolve renderer configuration ↓Assign runtime animation states ↓Test fallback, input, cleanup,hydration, and renderer behaviorThis is the useful goal for configurable effect architecture: presets should describe intentional visual variation, overrides should have explicit limits, environment policy should be able to overrule unsafe assumptions, and the renderer should remain technically coherent.
When those contracts materially change, another preset is usually not the solution.
Browse source-first React and Next.js effects, inspect their dependencies, and adapt the implementation to your project's interaction needs.





