Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Created May 1, 2016 23:20
Show Gist options
  • Save postspectacular/9de41cb7d9d6c4f264715b7d2fc966c0 to your computer and use it in GitHub Desktop.
Save postspectacular/9de41cb7d9d6c4f264715b7d2fc966c0 to your computer and use it in GitHub Desktop.
Reagent canvas component
(ns canvas
(:require
[thi.ng.geom.gl.webgl.animator :as anim]
[reagent.core :as reagent]))
(defn canvas-component
[props]
(reagent/create-class
{:component-did-mount
(fn [this]
(reagent/set-state this {:active true})
((:init props) this)
(anim/animate ((:loop props) this)))
:component-will-unmount
(fn [this]
(reagent/set-state this {:active false}))
:reagent-render
(fn [_]
[:canvas
(merge
{:width (.-innerWidth js/window)
:height (.-innerHeight js/window)}
props)])}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment