Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@
if (typeof define === 'function' && define.amd) {
define(['react', 'backbone', 'underscore'], factory);
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = factory(require('react'), require('backbone'), require('underscore'));
var react = null;
var isReactNative = false;
try {
react = require('react');
} catch (error) {
react = require('React'); // React Native
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a while ago a React Native example project and the way the library is required is with require('react-native'). Are you sure about React?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find the source file in here

isReactNative = true;
}
module.exports = factory(isReactNative, react, require('backbone'), require('underscore'));
} else {
factory(root.React, root.Backbone, root._);
}
}(this, function (React, Backbone, _) {
}(this, function (isReactNative, React, Backbone, _) {
'use strict';
if (!Backbone.React) {
Backbone.React = {};
Expand Down Expand Up @@ -70,11 +78,15 @@
},
// Sets `this.el` and `this.$el` when the component mounts.
componentDidMount: function () {
this.setElement(React.findDOMNode(this));
if (isReactNative === false) {
this.setElement(React.findDOMNode(this));
}
},
// Sets `this.el` and `this.$el` when the component updates.
componentDidUpdate: function () {
this.setElement(React.findDOMNode(this));
if (isReactNative === false) {
this.setElement(React.findDOMNode(this));
}
},
// When the component gets the initial state, instance a `Wrapper` to take
// care of models and collections binding with `this.state`.
Expand Down