Skip to content

Commit 53be0a8

Browse files
author
Clauderic Demers
committed
🐛 Fix dev environment example code
1 parent 8562a3d commit 53be0a8

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

index.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,48 @@ import {SortableContainer, SortableElement, arrayMove} from './src/index';
55
import range from 'lodash/range';
66
import random from 'lodash/random';
77

8-
const Item = SortableElement((props) => {
9-
return (
10-
<div style={{
11-
position: 'relative',
12-
width: '100%',
13-
display: 'block',
14-
padding: 20,
15-
borderBottom: '1px solid #DEDEDE',
16-
boxSizing: 'border-box',
17-
WebkitUserSelect: 'none',
18-
height: props.height
19-
}}>
20-
Item {props.value}
21-
</div>
22-
)
23-
});
8+
const SortableItem = SortableElement(({height, value}) => (
9+
<div style={{
10+
position: 'relative',
11+
width: '100%',
12+
display: 'block',
13+
padding: 20,
14+
borderBottom: '1px solid #DEDEDE',
15+
boxSizing: 'border-box',
16+
WebkitUserSelect: 'none',
17+
height: height
18+
}}>
19+
Item {value}
20+
</div>
21+
));
2422

25-
class List extends Component {
23+
const SortableList = SortableContainer(({items}) => (
24+
<div>
25+
{items.map(({height, value}, index) => <SortableItem key={`item-${index}`} index={index} value={value} height={height}/>)}
26+
</div>
27+
));
28+
29+
class Example extends Component {
2630
state = {
27-
items: range(5000).map((value) => {
31+
items: range(100).map((value) => {
2832
return {
2933
value,
3034
height: random(49, 120)
3135
};
3236
})
3337
};
34-
onSortEnd = (previousIndex, newIndex) => {
38+
onSortEnd = ({oldIndex, newIndex}) => {
3539
let {items} = this.state;
36-
arrayMove(items, previousIndex, newIndex);
40+
arrayMove(items, oldIndex, newIndex);
3741
this.setState({items});
3842
};
3943
render() {
4044
const {items} = this.state;
4145

42-
return (
43-
<div>
44-
{items.map((item, index) => <Item key={`item-${index}`} index={index} value={item}/>)}
45-
</div>
46-
);
46+
return <SortableList items={items} onSortEnd={this.onSortEnd} />;
4747
}
4848
}
4949

50-
const SortableList = SortableContainer(List);
51-
52-
render(<SortableList />,
50+
render(<Example />,
5351
document.getElementById('root')
5452
)

0 commit comments

Comments
 (0)