我的目标是渲染我的LinkContainer
组件,以便它们在我的拖放上下文中:
<DragDropContext onDragEnd={handleOnDragEnd}>
<Droppable droppableId="characters">
{(provided) => (
<ul
className="characters"
{...provided.droppableProps}
ref={provided.innerRef}
>
{links.map((l, index) => {
return (
<Draggable key={l.id} draggableId={l.id} index={index}>
{(provided) => (
<li
className="draggable"
{...provided.draggableProps}
{...provided.dragHandleProps}
ref={provided.innerRef}
>
<LinkContainer
linkTitle={l.linkTitle}
/>
</li>
)}
</Draggable>
);
})}
</ul>
)}
</Droppable>
</DragDropContext>
这是允许我在设置links
新订单的同时进行拖放的功能:
const reorder = (links, startIndex, endIndex) => {
const result = Array.from(links);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);
return result;
};
// handle drag end
const handleOnDragEnd = (result) => {
console.log(result);
setLinks(reorder(links, result.source.index, result.destination.index));
};
如何更新我的 firebase 记录,LinkContainer
以便在links
页面重新加载时映射到最后一个顺序?
我是否必须在文档本身上创建一个索引并更新它的位置 LinkContainer