Skip to content

Instantly share code, notes, and snippets.

@IcanDivideBy0
IcanDivideBy0 / useCanvas.js
Last active September 28, 2021 03:14
Simple hook for canvas rendering in react
import React from "react";
// Usage
function App() {
const draw = React.useCallback(gl => {
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clearDepth(1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
}, []);
const canvasRef = useCanvas(draw, "webgl2");