-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I'm using react-draggable in my application to scroll an item in a viewport (i.e. dragging the background scrolls the view), and also for custom scrollbars around the viewport. Needless to say, I needed to use the moveOnStartChange attribute to keep these two manners of scrolling the same viewport consistent. I found, however, that there was some really buggy behavior in react-draggable, and it stemmed from the fact that componentWillReceiveProps triggers too often.
If you declare your component like this:
<Draggable start={{x: 0, y: 0}}>...</Draggable>
then every time the render() method is called, the componentWillReceiveProps method is called because, technically, a new object is being passed as the 'start' property.
The solution I have come up with is to change lines 471-473 in the componentWillReceiveProps method to:
if (newProps.moveOnStartChange && newProps.start &&
(newProps.start.x !== this.props.start.x || newProps.start.y !== this.props.start.y))
{
this.setState(this.getInitialState(newProps));
}
Thoughts?