Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #108 "ref is not a prop" error #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
45 changes: 36 additions & 9 deletions dist/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.InfiniteScroll = undefined;

var _createClass = (function() {
function defineProperties(target, props) {
Expand All @@ -21,6 +22,20 @@ var _createClass = (function() {
};
})();

var _extends =
Object.assign ||
function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};

var _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand Down Expand Up @@ -81,7 +96,21 @@ function _inherits(subClass, superClass) {
: (subClass.__proto__ = superClass);
}

var InfiniteScroll = (function(_Component) {
exports.default = _react2.default.forwardRef(function(props, ref) {
return _react2.default.createElement(
InfiniteScroll,
_extends({}, props, {
forwardedRef:
typeof ref === 'function'
? ref
: function(r) {
return (ref = r);
}
})
);
});

var InfiniteScroll = (exports.InfiniteScroll = (function(_Component) {
_inherits(InfiniteScroll, _Component);

function InfiniteScroll(props) {
Expand Down Expand Up @@ -357,7 +386,7 @@ var InfiniteScroll = (function(_Component) {
loader = renderProps.loader,
loadMore = renderProps.loadMore,
pageStart = renderProps.pageStart,
ref = renderProps.ref,
forwardedRef = renderProps.forwardedRef,
threshold = renderProps.threshold,
useCapture = renderProps.useCapture,
useWindow = renderProps.useWindow,
Expand All @@ -371,7 +400,7 @@ var InfiniteScroll = (function(_Component) {
'loader',
'loadMore',
'pageStart',
'ref',
'forwardedRef',
'threshold',
'useCapture',
'useWindow',
Expand All @@ -380,8 +409,8 @@ var InfiniteScroll = (function(_Component) {

props.ref = function(node) {
_this2.scrollComponent = node;
if (ref) {
ref(node);
if (forwardedRef) {
forwardedRef(node);
}
};

Expand All @@ -403,7 +432,7 @@ var InfiniteScroll = (function(_Component) {
]);

return InfiniteScroll;
})(_react.Component);
})(_react.Component));

InfiniteScroll.propTypes = {
children: _propTypes2.default.node.isRequired,
Expand All @@ -414,7 +443,7 @@ InfiniteScroll.propTypes = {
loader: _propTypes2.default.node,
loadMore: _propTypes2.default.func.isRequired,
pageStart: _propTypes2.default.number,
ref: _propTypes2.default.func,
forwardedRef: _propTypes2.default.func,
getScrollParent: _propTypes2.default.func,
threshold: _propTypes2.default.number,
useCapture: _propTypes2.default.bool,
Expand All @@ -433,5 +462,3 @@ InfiniteScroll.defaultProps = {
loader: null,
getScrollParent: null
};
exports.default = InfiniteScroll;
module.exports = exports['default'];
17 changes: 12 additions & 5 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

export default class InfiniteScroll extends Component {
export default React.forwardRef((props, ref) => (
<InfiniteScroll
{...props}
forwardedRef={typeof ref === 'function' ? ref : r => (ref = r)}
/>
));

export class InfiniteScroll extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
element: PropTypes.node,
Expand All @@ -11,7 +18,7 @@ export default class InfiniteScroll extends Component {
loader: PropTypes.node,
loadMore: PropTypes.func.isRequired,
pageStart: PropTypes.number,
ref: PropTypes.func,
forwardedRef: PropTypes.func,
getScrollParent: PropTypes.func,
threshold: PropTypes.number,
useCapture: PropTypes.bool,
Expand Down Expand Up @@ -256,7 +263,7 @@ export default class InfiniteScroll extends Component {
loader,
loadMore,
pageStart,
ref,
forwardedRef,
threshold,
useCapture,
useWindow,
Expand All @@ -266,8 +273,8 @@ export default class InfiniteScroll extends Component {

props.ref = node => {
this.scrollComponent = node;
if (ref) {
ref(node);
if (forwardedRef) {
forwardedRef(node);
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/infiniteScroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { mount } from 'enzyme';
import { expect } from 'chai';
import { stub, spy } from 'sinon';
import InfiniteScroll from '../src/InfiniteScroll';
import { InfiniteScroll } from '../src/InfiniteScroll';

describe('InfiniteScroll component', () => {
it('should render', () => {
Expand Down