简体   繁体   English

React Beautiful DND Invariant 在可拖动和可放置的 id 上失败

[英]React Beautiful DND Invariant failed on draggable and droppable ids

Trying to figure out why I can't drag and drop my items (I get a hand over the list elements, but no ability to pick them up).试图找出为什么我不能拖放我的项目(我得到了列表元素的手,但无法拾取它们)。 I followed a tutorial to a T and i'm not sure why it's failing.我遵循了 T 的教程,但我不确定它为什么会失败。 I'm not concerned with list order or out of bounds dragging right now, just being able to drag at all.我现在不关心列表顺序或越界拖动,只是能够拖动。

I get the following errors:我收到以下错误:

A setup problem was encountered.遇到设置问题。 > Invariant failed: Draggable requires a draggableId > 不变失败:Draggable 需要一个 draggableId

A setup problem was encountered.> Invariant failed: A Droppable requires a droppableId prop遇到设置问题。> 不变量失败:Droppable 需要一个 droppableId 道具

However, I believe I have all the necessary IDs on my elements.但是,我相信我的元素上有所有必要的 ID。 Here is my code (pls enjoy the sheRa references)这是我的代码(请欣赏 sheRa 参考资料)

import React from "react";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";

const sheRaCharacters = [
  {
    id: "Adora",
    name: "Adora",
    color: "#FFD700",
  },
  {
    id: "Catra",
    name: "Catra",
    color: "#ff0000",
  },
  {
    id: "Entrapta",
    name: "Entrapta",
    color: "purple",
  },
  {
    id: "Mermista",
    name: "Mermista",
    color: "#0000ff",
  },
];

class DragDropTest extends React.Component {

  render() {
    const listStyle = {
      backgroundColor: "pink",
      padding: "10px",
      margin: "8px",
      borderRadius: "8px",
    };

    const characterList = sheRaCharacters.map(({ id, name, color }, index) => {
      return (
        <Draggable key={id} draggableID={id} index={index}>
          {(provided) => (
            <li
              ref={provided.innerRef}
              {...provided.draggableProps}
              {...provided.dragHandleProps}
              style={listStyle}
            >
              <p style={{ color: color }}>{name}</p>
            </li>
          )}
        </Draggable>
      );
    });

    return (
      <div>
        <DragDropContext>
          <Droppable droppableID="characters">
            {(provided) => (
              <ul ref={provided.innerRef} {...provided.droppableProps}>
                {characterList}
                {provided.placeholder}
              </ul>
            )}
          </Droppable>
        </DragDropContext>
      </div>
    );
  }
}

export default DragDropTest;

So the droppable area has a string ID and all the draggable elements also have string IDs.所以可放置区域有一个字符串 ID,所有可拖动元素也有一个字符串 ID。 What did I miss?我错过了什么?

JS is case sensitive so you must write 'draggableId' instead 'draggableID' JS 区分大小写,所以你必须写 'draggableId' 而不是 'draggableID'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将组件拖放到同一Droppable react-beautiful-dnd中 - Unable to drag and drop Components in same Droppable react-beautiful-dnd 用于 react-beautiful-dnd 抛出错误构建 Droppable 的寓言绑定 - Fable Bindings for react-beautiful-dnd throwing error building Droppable React / Dnd:同时使组件可拖动和可拖放 - React/Dnd: Make a component draggable and droppable at the same time 如何使我的 react-dnd 可放置组件也可拖动? - How to make my react-dnd droppable component draggable too? 有没有一种方法可以向react-dnd中的可拖放项目添加标签 - Is there a way to add a label to draggable and droppable items in react-dnd react-beautiful-dnd draggable 在拖动过程中不可见 - react-beautiful-dnd draggable not visible during drag 如何在 react-beautiful-dnd 中将 onDragStart 附加到 Draggable? - How to attach onDragStart to Draggable in react-beautiful-dnd? 找不到 ID 为 x 的可拖动对象 - reactjs - react-beautiful-dnd - Unable to find draggable with id x - reactjs - react-beautiful-dnd React 美丽的 DND - 我得到“无法找到带有 id 的可拖动对象:1” - React beautiful DND - I get "Unable to find draggable with id: 1" 反应材质UI<listitemsecondaryaction> 在 react-beautiful-dnd Draggable 中拖动时卡住了?</listitemsecondaryaction> - React MaterialUI <ListItemSecondaryAction> gets stuck when dragging inside react-beautiful-dnd Draggable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM