如何使用 Immutable 表示这个数组重新排序示例?
How to represent this array re-ordering example using Immutable?
来自 react-dnd 的代码示例:
https://github.com/gaearon/react-dnd/blob/master/examples/04%20Sortable/Simple/Container.js#L46-L53
this.setState(update(this.state, {
cards: {
$splice: [
[dragIndex, 1],
[hoverIndex, 0, dragCard]
]
}
}));
我正在尝试使用 Immutable 执行相同的操作,但不知道如何操作。
知道了!
const cards = state.get('cards');
const newState = state.set('cards',
cards.splice(dragIndex, 1)
.splice(hoverIndex, 0, dragCard));
来自 react-dnd 的代码示例:
https://github.com/gaearon/react-dnd/blob/master/examples/04%20Sortable/Simple/Container.js#L46-L53
this.setState(update(this.state, {
cards: {
$splice: [
[dragIndex, 1],
[hoverIndex, 0, dragCard]
]
}
}));
我正在尝试使用 Immutable 执行相同的操作,但不知道如何操作。
知道了!
const cards = state.get('cards');
const newState = state.set('cards',
cards.splice(dragIndex, 1)
.splice(hoverIndex, 0, dragCard));