【发布时间】:2020-12-06 16:59:14
【问题描述】:
我的目标是渲染我的 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 记录,以便在重新加载页面上通过 links 映射时,LinkContainer 以最后的顺序呈现?
我是否必须在文档本身上创建一个索引并使用LinkContainer 的位置更新它
【问题讨论】:
标签: reactjs firebase google-cloud-firestore