react-three-renderer
====================
## PSA:
This project is pretty much frozen and the react-three-renderer-fiber project has been moving at a glacial rate. If you'd like to contribute to the React + Three bridge ecosystems, please take a look at how you can help with the more active https://github.com/drcmda/react-three-fiber project instead.
## Back to regular readme
Render into a [three.js](http://threejs.org/) canvas using [React](https://github.com/facebook/react).
Would you like to know more? [See the wiki](https://github.com/toxicFork/react-three-renderer/wiki) or go straight to the [API documentation](https://github.com/toxicFork/react-three-renderer/wiki/API-Reference).
[Live examples](http://toxicfork.github.io/react-three-renderer-example/).
[](https://gitter.im/toxicFork/react-three-renderer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://travis-ci.org/toxicFork/react-three-renderer)
[](https://nodei.co/npm/react-three-renderer/)
Current State
=============
This is still an experimental and work in progress project, use at your own risk!
Currently supported react version: `15.5.3` ( things break fast when you fly this close to the sun )
This project is being maintained and developed relatively slowly.
Currently we're working on restoring compatibility with React 16 - Fiber edition!
See work in progress within https://github.com/toxicFork/react-three-renderer-fiber.
Expected ETA: Unknown.
Installation
============
```
npm install --save react@15.6.1 react-dom@15.6.1 three@0.86.0
npm install --save react-three-renderer
```
Usage
=====
The default export of the module is a react component. When mounted, any children of it will be placed into the three.js
environment.
Here's a simple example that implements the [getting started scene for three.js](https://threejs.org/docs/#manual/introduction/Creating-a-scene).
```js
import React from 'react';
import React3 from 'react-three-renderer';
import * as THREE from 'three';
import ReactDOM from 'react-dom';
class Simple extends React.Component {
constructor(props, context) {
super(props, context);
// construct the position vector here, because if we use 'new' within render,
// React will think that things have changed when they have not.
this.cameraPosition = new THREE.Vector3(0, 0, 5);
this.state = {
cubeRotation: new THREE.Euler(),
};
this._onAnimate = () => {
// we will get this callback every frame
// pretend cubeRotation is immutable.
// this helps with updates and pure rendering.
// React will be sure that the rotation has now updated.
this.setState({
cubeRotation: new THREE.Euler(
this.state.cubeRotation.x + 0.1,
this.state.cubeRotation.y + 0.1,
0
),
});
};
}
render() {
const width = window.innerWidth; // canvas width
const height = window.innerHeight; // canvas height
return (