gl-react: Writing WebGL Shaders as Composable React Components
gl-react – React library to write and compose WebGL shaders
At a glance
- What is it?
- gl-react is a React library for writing and composing WebGL shaders, paired with a concrete backend such as gl-react-dom or gl-react-expo. The design is sound and the v6 release refreshed the toolchain, but the headless Node path and the thin documentation for non-DOM targets are the parts to check before adopting.
- Who is it for?
- Adopt gl-react if you are already shipping React and want shader effects expressed as components with props and a normal lifecycle, and if your target is gl-react-dom or gl-react-expo. Do not adopt it if you need a Node-only renderer: gl-react-headless exists in the repository but the README gives no install or usage steps for it, so verify that backend against the packages/gl-react-headless source before committing.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 6 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- gre/gl-react3,020 ★ · +12
| Repository | 2026-09-24 | 2026-11-22 |
|---|---|---|
| gre/gl-react | 3k | 3k |
12 Stars in the last 59 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The problem gl-react solves: shaders that behave like React components
OpenGL is an imperative, mutable API. You create a context, compile programs, bind uniforms, draw, and clean up, and the ordering is yours to manage by hand. React is descriptive: you return a tree and the runtime reconciles it. gl-react sits between the two. The README frames the goal as taking OpenGL and exposing it "in an immutable, descriptive way with React", and the concrete payoff is that a fragment shader becomes a component you can nest inside another component, pass props to, and inspect in React DevTools.
The audience is narrower than "React developers". It is people building image effects, video filters, generative visuals or GPU-composited UI who already think in React and do not want to hand-write a WebGL bootstrap for every effect. If your work is a map, a chart or a 3D scene graph, this is not the layer you want; the related searches that pair gl-react with Mapbox GL, MapLibre and deck.gl are looking for something else.
One structural point matters more than any feature list: gl-react is a universal package and does nothing on its own. The README states it "must be coupled with one of the concrete implementations". The rendering surface comes from gl-react-dom, gl-react-expo, gl-react-native or gl-react-headless. Choosing the wrong one is the first failure mode a new user hits.
How the Node, Shaders and Surface pieces fit together
The mechanism is a small set of exported primitives. Shaders.create takes a map of named shader definitions, each with a frag field holding a GLSL string produced by the GLSL tagged template literal. Node renders one shader instance and takes a uniforms prop. Surface comes from the backend package and owns the actual canvas or GL view.
The data flow described in the README is a redraw-on-update model. Each Node holds a framebuffer state, and that state is redrawn when the component updates, which in turn schedules a reflow of the Surface. That is what the README means by partial GL re-rendering: only a React component update triggers a redraw. For a static image this is close to free. For an animation you are driving the loop through React state or props, and that is a real constraint rather than a detail, because React's update path is not the same as a requestAnimationFrame loop and you will feel the difference at high frame rates.
Uniform binding is the part that saves the most typing. The library maps JavaScript objects onto GLSL types: bool, int, float, vec2 through vec4, mat2 through mat4, and sampler2D. A texture is just a prop, and the README describes an extensible texture loader with support for images, plus videos and canvas on gl-react-dom. That loader is the extension point if you need a source the library does not ship.
The composition story is the reason to pick this over raw WebGL. A Node can consume the output of another Node as a sampler2D, so a chain of effects is a chain of nested components, and the README's closing claim is that "users don't need to write shaders" once the components exist. That is the shareable-unit argument, and it is the strongest thing in the design.
Installing gl-react and rendering a first shader
The repository is a pnpm workspace and the root package.json enforces it: a preinstall script exits with an error unless the npm exec path contains pnpm, printing "Please use pnpm". So the install is not optional tooling preference, it is a hard gate in the repository itself. Note that this applies to the monorepo; consuming the published packages from npm is a separate question the README does not address.
To work on the library or read the examples, install with pnpm and then start the cookbook, which the README lists as the way to run the examples locally.
pnpm install
pnpm cookbookThe cookbook script is defined in package.json as a filter on the gl-react-cookbook package, so it runs the example app from packages/cookbook rather than the library sources.
For application code, the README's gist defines a shader and a component. The shader is a fragment program in GLSL, and the component passes a uniform into a Node.
import React from "react";
import { Shaders, Node, GLSL } from "gl-react";
const shaders = Shaders.create({
helloBlue: {
frag: GLSL`
precision highp float;
varying vec2 uv;
uniform float blue;
void main() {
gl_FragColor = vec4(uv.x, uv.y, blue, 1.0);
}`
}
});Then you import a Surface from exactly one backend package. The README lists four: gl-react-dom for React DOM, gl-react-expo for React Native via Expo GLView, gl-react-native for React Native, and gl-react-headless for Node.js.
import { Surface } from "gl-react-dom"; // for React DOMWrapping the component in a Surface with explicit width and height is what actually renders. The README's example uses 300 by 300 and a blue value of 0.5.
<Surface width={300} height={300}>
<HelloBlue blue={0.5} />
</Surface>If you use Vite, the README documents one required change. gl-react depends on typedarray-pool, which references Node's global, so vite.config.js needs a define entry mapping global to globalThis.
export default defineConfig({
// ...
define: {
global: "globalThis",
},
});Without that, the README implies the bundle fails on the missing global. That is the kind of detail that costs an afternoon if you find it after the error rather than before.
Where gl-react gets in your way
The redraw model is the first limitation, and it is a design choice rather than a bug. Because a redraw is scheduled by a component update, an effect that needs to run continuously is coupled to React's update cycle. The README presents this as a feature (partial re-rendering, no wasted draws) and it is, for static composition. For a real-time animation driven by a clock, you are pushing values through props on every frame, and nothing in the README describes a bypass for that.
The second limitation is backend coverage that is uneven and thinly documented. The README says video and canvas texture sources are supported on gl-react-dom specifically, which implies they are not available on the other backends. gl-react-native is described as backed by the Expo implementation over unimodules, which is a heavier dependency than the name suggests. And gl-react-headless, the Node.js path, is listed as a package but the README gives no install command, no usage example and no note on what headless-gl requires on the host. If server-side rendering of shader output is your reason for looking at this library, the README does not support that decision on its own.
Third, the repository's own typecheck script is a stub. It prints "TODO: tsc -b (needs peerDep resolution for PnP)" instead of running the compiler. The library ships TypeScript sources and the README advertises flowtype support, but a monorepo that cannot run a typecheck in its default script is telling you something about the state of the typing story. Treat the published type definitions as the thing to verify in your own project, not the repository's internal setup.
Finally, there is a TRADEOFFS.md at the repository root. The README does not summarize it, so anyone weighing this library against an alternative should read that file directly rather than trusting a feature list.
gl-react compared with writing raw WebGL or using a scene-graph library
The honest alternative is plain WebGL: get a context from a canvas, compile your vertex and fragment shaders, set up a program, bind attributes and uniforms, and draw. That gives you a requestAnimationFrame loop you control completely, no React reconciliation in the frame path, and no extra dependency. The cost is that every effect is bespoke plumbing, and composing two effects means writing the framebuffer and texture-swap code yourself. gl-react's answer to that is the Node tree, where one Node's output feeds another as a sampler2D and the framebuffer management is the library's problem. If you have one shader and no composition, raw WebGL is less machinery.
The other family of alternatives is the GPU scene-graph and mapping stack. The related searches here are dominated by Mapbox GL, MapLibre GL, react-map-gl and deck.gl, and those solve a different problem: they render geographic tiles and data layers on a GPU. They are not shader composition libraries. If what you actually want is a map with a custom layer, gl-react is the wrong layer of the stack, even though both end up in WebGL. The same applies to vis.gl and google-maps wrappers that appear in the search list; the naming overlap is the only thing they share with this project.
Within the gl-react family itself, the meaningful choice is the backend, not a competitor. gl-react-dom gives you the browser and the widest texture support. gl-react-expo and gl-react-native give you iOS and Android through Expo's GLView. gl-react-headless is the Node path. Picking between them is the actual decision, and the README documents gl-react-dom most thoroughly.
Version 6, the MIT licence and what upgrades cost
The v6.0.0 release is dated 2026-06-03, and the last push to the default branch was on 2026-09-19, so the repository is being touched. The gap before that is the relevant history: v5.2.0 landed on 2022-05-28 and v5.1.0 on 2021-03-13. Three and a half years passed between the v5 line and v6. If you adopted gl-react in 2022, you have been on a stable but essentially frozen API for most of that time, and v6 is the first real migration event since.
The repository uses Changesets: there is a .changeset directory, the @changesets/cli dev dependency, a changeset script and a release script that runs pnpm build before changeset publish. That means the upgrade path is documented per release in changeset files rather than in the README, and reading those files is how you find out what v6 broke. Nothing in the README describes the v5 to v6 migration, so treat the changeset entries as the source.
The licence is MIT, declared in both the LICENSE file and the root package.json. MIT is permissive: it allows commercial and closed-source use with attribution and no warranty. That is the whole of what the repository states, and it is not legal advice; if your organisation has specific obligations around attribution or patent language, have someone qualified read the actual LICENSE text.
One practical upgrade cost sits in the toolchain rather than the API. The root package.json pins pnpm 10.34.3 as the package manager and overrides a list of transitive dependencies, including gl at 9.0.0-rc.9. That gl pin is a release candidate for the headless backend, which is worth knowing if gl-react-headless is part of your plan.
Editorial conclusion
Adopt gl-react if you are already shipping React and want shader effects expressed as components with props and a normal lifecycle, and if your target is gl-react-dom or gl-react-expo. Do not adopt it if you need a Node-only renderer: gl-react-headless exists in the repository but the README gives no install or usage steps for it, so verify that backend against the packages/gl-react-headless source before committing. Also skip it if you want a map layer, since the related searches around Mapbox GL and deck.gl point at different libraries. First verify the Vite global shim and the pnpm-only install, then run pnpm cookbook and confirm the cookbook renders on your target before porting any existing shader.
Frequently asked questions
What is gl-react used for?
It is a React library for writing and composing WebGL shaders, so that effects are expressed as React components with props and a normal lifecycle. The README's stated goal is to expose OpenGL in an immutable, descriptive way with React, and to let users compose complex effects by nesting components.
How do I install gl-react?
The repository is a pnpm workspace and its preinstall script exits unless the npm exec path contains pnpm, so the monorepo installs with pnpm. The README does not give npm install steps for the published packages, only the repository workflow and the cookbook command.
Does gl-react work with React Native and Expo?
Yes. The README lists gl-react-native for React Native on iOS and Android, backed by the Expo implementation over unimodules, and gl-react-expo for React Native through Expo's GLView. Each is a separate backend package that supplies the Surface component.
Which gl-react package should I import for React DOM?
gl-react-dom. The README shows importing Surface from gl-react-dom for React DOM, and it is also the backend where video and canvas texture sources are supported.
Does gl-react need a Vite configuration change?
Yes, if you bundle with Vite. The README states that gl-react uses typedarray-pool, which references Node's global, and instructs adding a define entry mapping global to globalThis in vite.config.js.
Can gl-react render shaders on a Node.js server?
The README lists gl-react-headless for Node.js, backed by headless-gl, as one of the concrete implementations to couple with the core library. It gives no install command or usage example for that package, so the repository source is the only place to confirm what it requires.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/gre-gl-react)Star history chart for your README
[](https://hysenlabs.com/projects/gre-gl-react)Was this useful?