Skip to content

Commit

Permalink
fix(canvas): add React props for canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
setsun committed Apr 5, 2019
1 parent 45d5e6f commit ed817db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 8 additions & 8 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"dist/index.js": {
"bundled": 23703,
"minified": 11181,
"gzipped": 4126,
"bundled": 23760,
"minified": 11202,
"gzipped": 4128,
"treeshaked": {
"rollup": {
"code": 9273,
"code": 9294,
"import_statements": 578
},
"webpack": {
"code": 10833
"code": 10854
}
}
},
"dist/index.cjs.js": {
"bundled": 26698,
"minified": 12883,
"gzipped": 4345
"bundled": 26755,
"minified": 12904,
"gzipped": 4349
}
}
14 changes: 12 additions & 2 deletions src/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useRef, useEffect, useState, useCallback } from 'react'
import ResizeObserver from 'resize-observer-polyfill'
import { invalidate, applyProps, render, unmountComponentAtNode } from './reconciler'

export const stateContext = React.createContext()
export const stateContext = React.createContext({})

function useMeasure() {
const ref = useRef()
Expand All @@ -16,8 +16,18 @@ function useMeasure() {
return [{ ref }, bounds]
}

type CanvasProps = {
children: React.ReactChildren;
gl: THREE.WebGLRenderer;
camera?: THREE.Camera;
style?: React.CSSProperties;
pixelRatio?: number;
invalidateFrameloop?: boolean;
onCreated: (ref: React.MutableRefObject<any>) => any,
}

export const Canvas = React.memo(
({ children, gl, camera, style, pixelRatio, invalidateFrameloop = false, onCreated, ...rest }) => {
({ children, gl, camera, style, pixelRatio, invalidateFrameloop = false, onCreated, ...rest }: CanvasProps) => {
// Local, reactive state
const canvas = useRef()
const [ready, setReady] = useState(false)
Expand Down

0 comments on commit ed817db

Please sign in to comment.