@shader-core/react
v1.0.0
Published
React components for Shader Core: <Shader> with layers as children.
Maintainers
Readme
@shader-core/react
React components for Shader Core.
import { Shader, Gradient, Curtains, Grain, Vignette } from '@shader-core/react';
<Shader>
<Gradient colorA="#04060f" colorB="#0a1230" />
<Curtains scale={3.8} colorSheet="#3ddc97" colorFilament="#4361ee" />
<Grain intensity={0.25} />
<Vignette amount={0.5} />
</Shader>;Children are layers, bottom to top, blended into one canvas. Each is typed from
its schema, so a mistyped prop is a compile error rather than a uniform nobody
sets. Every layer also has its own entry point — @shader-core/react/gradient —
if you would rather not rely on tree-shaking.
Changing a prop updates a uniform. Adding, removing or reordering a child
changes the stack and recompiles once, then it is cached. dispose() runs on
unmount, including the extra mount React's development mode performs.
Children must be layers
Layer components and fragments only. A component that wraps layers cannot be
read without rendering it, so inline the layers or have the component return its
own <Shader>. <Shader> says so by name if you get this wrong.
Props
className, style, quality, reducedMotion, staticTime, onError.
Nothing here throws into an error boundary: a background is not worth taking a
page down for, so failures go to onError (or the console) and the canvas stays
blank.
React is a peer dependency, >=18.
Licence
Free to use, including commercially. See LICENSE.md.
