【发布时间】:2022-01-12 14:38:29
【问题描述】:
事情就是这样。我正在通过构建一个待办事项应用程序来学习 React 美丽的 dnd。而且我已经设置了应用程序的样式,并编写了显示待办事项卡的逻辑。
问题是这样的,当我将卡片拖到待办事项中以进行或完成时,在控制台中记录的对象中的属性“destination”(检查代码以查看记录的位置)destination 等于 null。它应该等于一个对象。似乎是什么问题。
The full code is located in the link below:
https://codesandbox.io/s/async-fast-hziot?file=/src/App.js
预览:
import "./styles.css";
import { useState } from "react";
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
export default function App() {
const [populateStore, setPopulateStore] = useState(
{
todo: {
_id:"todo",
data: [
{
_id: 'ms7690fvs6sd53h328sof-0sdf',
author: 'anonymous',
title: 'Going to the pack',
date: '11th, January 2022'
},
{
_id: 'sdfdf32gf98tddswjk73i2r',
author: 'anonymous',
title: 'Visit my parents for the holiday',
date: '11th, January 2022'
}
]},
inprogress: {
_id: "in progress",
data:[]},
done: {
_id:"done",
data: []
}
}
);
function handleOnDragEnd(result) {
console.log(result, "result")
}
return (
<div className="populate-container">
{Object.entries(populateStore).map(([title, array],index) => {
return (
<div className="todo-container" key={index}>
<div className="todo-headings">
{title}
</div>
<DragDropContext onDragEnd={handleOnDragEnd}>
<Droppable
droppableId={`${array._id}`}
type={`${array._id}`}
>
{
(provided) => {
return (
<div className="_droppable" {...provided.droppableProps} ref={provided.innerRef}>
{
array.data.map((item, id) => {
return (
<Draggable key={id} draggableId={`${id}`} index={id}>
{
(provided) => {
return (
<div className="card" ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps} key={id}>
<div className="card-description">
<h5>{item.title}</h5>
<p>
{
item.date
}
</p>
</div>
</div>
)
}
}
</Draggable>
)
})
}
{provided.placeholder}
</div>
)
}
}
</Droppable>
</DragDropContext>
</div>
)
})}
</div>
);
}
【问题讨论】:
标签: reactjs react-beautiful-dnd