Skip to content

Commit cf44fbd

Browse files
author
Claudéric Demers
authored
Update infinite-list.js
1 parent c795989 commit cf44fbd

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

examples/infinite-list.js

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,46 @@ import {SortableContainer, SortableElement, arrayMove} from 'react-sortable-hoc'
44
import Infinite from 'react-infinite';
55

66
const SortableItem = SortableElement(({height, value}) => {
7-
return (
8-
<li style={{height}}>
9-
{value}
10-
</li>
11-
)
7+
return (
8+
<li style={{height}}>
9+
{value}
10+
</li>
11+
);
1212
});
1313

1414
const SortableList = SortableContainer(({items}) => {
15-
return (
16-
<Infinite
17-
containerHeight={600}
18-
elementHeight={items.map(({height}) => height)}
19-
>
20-
{items.map(({value, height}, index) => <SortableItem key={`item-${index}`} index={index} value={value} height={height}/>)}
21-
</Infinite>
22-
);
15+
return (
16+
<Infinite containerHeight={600} elementHeight={items.map(({height}) => height)}>
17+
{items.map(({value, height}, index) => (
18+
<SortableItem key={`item-${index}`} index={index} value={value} height={height} />
19+
))}
20+
</Infinite>
21+
);
2322
});
2423

25-
2624
class SortableComponent extends Component {
27-
state = {
28-
items: [
29-
{value: 'Item 1', height: 89},
30-
{value: 'Item 2', height: 59},
31-
{value: 'Item 3', height: 130},
32-
{value: 'Item 4', height: 59},
33-
{value: 'Item 5', height: 200},
34-
{value: 'Item 6', height: 150}
35-
]
36-
}
37-
onSortEnd = ({oldIndex, newIndex}) => {
38-
let {items} = this.state;
25+
state = {
26+
items: [
27+
{value: 'Item 1', height: 89},
28+
{value: 'Item 2', height: 59},
29+
{value: 'Item 3', height: 130},
30+
{value: 'Item 4', height: 59},
31+
{value: 'Item 5', height: 200},
32+
{value: 'Item 6', height: 150},
33+
],
34+
};
35+
onSortEnd = ({oldIndex, newIndex}) => {
36+
let {items} = this.state;
3937

40-
this.setState({
41-
items: arrayMove(items, oldIndex, newIndex)
42-
});
43-
};
44-
render() {
45-
let {items} = this.state;
38+
this.setState({
39+
items: arrayMove(items, oldIndex, newIndex),
40+
});
41+
};
42+
render() {
43+
let {items} = this.state;
4644

47-
return (
48-
<SortableList items={items} onSortEnd={this.onSortEnd} />
49-
)
50-
}
45+
return <SortableList items={items} onSortEnd={this.onSortEnd} />;
46+
}
5147
}
5248

5349
render(<SortableComponent />, document.getElementById('root'));

0 commit comments

Comments
 (0)