3.1.0 • Published 5 years ago

@react-vertex/gl-context v3.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@react-vertex/gl-context

license bundlephobia npm version

Documentation and Examples

A React component to render a canvas and create a WebGL context. It uses the render prop pattern. For SSR this component will not render its children. Note: it's not required to use this component to use the other hook packages.

Install via npm:
npm install @react-vertex/gl-context

Importing:

import GlContext from '@react-vertex/gl-context'
Props:

width: Number for width of canvas element (defaults to 1).

height: Number for height of canvas element (defaults to 1).

antialias (optional): Boolean to turn on antialiasing (defaults to false).

canvasClass (optional): String class to be added to the canvas.

canvasStyle (optional): An object of styles to be applied to the canvas.

extensions (optional): An array of strings identifying the WebGL extensions you want loaded in the context.

contextAttrs (optional): An object of context attributes you want applied.

children: A function that accepts the context (gl) and an array of the extension return values (if using any extensions are being used) defaults to an empty array.

Example Usage:
import React, { useRef } from 'react'
import GLContext from '@react-vertex/gl-context'
import { useMeasure } from '@react-vertex/dom-hooks'

function Example() {
  const container = useRef()
  const { width } = useMeasure(container)

  return (
    <div ref={container}>
      <GLContext
        width={width}
        height={width}
        canvasStyle={{
          borderRadius: 4
        }}
      >
        {(gl, extensions) => (
          <Scene gl={gl} extensions={extensions} />
        )}
      </GLContext>
    </div>
  )
}

export default Example
3.1.0

5 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.11

5 years ago