Skip to content

Commit c41ba87

Browse files
committed
Improve perf
1 parent d2dbf37 commit c41ba87

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

examples/_sortable-simple/Container.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { configureDragDropContext, HTML5Backend } from 'react-dnd';
88
class Container extends Component {
99
constructor(props) {
1010
super(props);
11+
12+
this.moveCard = this.moveCard.bind(this);
13+
1114
this.state = {
1215
cards: [{
1316
id: 1,
@@ -62,7 +65,7 @@ class Container extends Component {
6265
<Card key={card.id}
6366
id={card.id}
6467
text={card.text}
65-
moveCard={(id, afterId) => this.moveCard(id, afterId)} />
68+
moveCard={this.moveCard} />
6669
);
6770
})}
6871
</div>

modules/configureDragDrop.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const HANDLE_SEPARATOR = '🍣';
1010

1111
export default function configureDragDrop(InnerComponent, { getHandlers, getProps, managerName = 'dragDropManager' }) {
1212
class DragDropContainer extends Component {
13+
shouldComponentUpdate(nextProps, nextState) {
14+
return !shallowEqual(nextProps, this.props) ||
15+
!shallowEqual(nextState, this.state);
16+
}
17+
1318
constructor(props, context) {
1419
super(props);
1520

@@ -31,6 +36,10 @@ export default function configureDragDrop(InnerComponent, { getHandlers, getProp
3136
}
3237

3338
componentWillReceiveProps(nextProps) {
39+
if (shallowEqual(nextProps, this.props)) {
40+
return;
41+
}
42+
3443
const monitor = this.manager.getMonitor();
3544

3645
monitor.removeChangeListener(this.handleChange);

0 commit comments

Comments
 (0)