react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

console.js:273 Warning: findDOMNode is deprecated and will be removed in the next major release.

Open HenrikBechmann opened this issue 1 year ago • 13 comments

This warning comes up now, and relates to "DraggableCore". This appears to be you...

Are you aware?

Screenshot 2024-04-27 at 9 27 12 AM

HenrikBechmann avatar Apr 27 '24 13:04 HenrikBechmann

yes, We also face same error

console.js:273 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of DraggableCore which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node
    at http://localhost:5173/node_modules/.vite/deps/chunk-QNSVWXN7.js?v=f5d60d48:758:49
    at Paper2 (http://localhost:5173/node_modules/.vite/deps/chunk-M4MEA2XN.js?v=f5d60d48:119:17)
    at DraggableCore (http://localhost:5173/node_modules/.vite/deps/react-draggable.js?v=f5d60d48:620:9)
    at Draggable (http://localhost:5173/node_modules/.vite/deps/react-draggable.js?v=f5d60d48:1067:9)
    at PaperComponent

React next major version don't have "FindDOMNode"

import { createRef, Component } from 'react';

class AutoselectingInput extends Component {
  inputRef = createRef(null);

  componentDidMount() {
    const input = this.inputRef.current;
    input.select()
  }

  render() {
    return (
      <input ref={this.inputRef} defaultValue="Hello" />
    );
  }
}

react-draggable should update there package !

theonlineaid avatar Apr 28 '24 06:04 theonlineaid

Same error here: image

yidah avatar May 02 '24 13:05 yidah

same here

fdemir avatar May 02 '24 15:05 fdemir

You can use the nodeRef prop documented in the README, it doesn't use findDOMNode and removes the warning.

floriancargoet avatar May 07 '24 14:05 floriancargoet

@floriancargoet the suggested fix in the readme does not fully cover all use cases.

Or at least I struggle to make it work. Image you want to use a react component in absolute positioning and it should be centered. After a few tries I couldn't find a way to include the suggested fixes, keep it draggable and still have it absolute positioned.

Here is a codebox to see what problem I try to describe. https://codesandbox.io/p/sandbox/react-draggable-absolute-center-problem-wtt5qg?file=%2Fsrc%2FApp.tsx%3A4%2C31

I could also open a new issue if you want me too, since my case is more specific, but in the end I came from the same origin.

julianhahn avatar May 24 '24 07:05 julianhahn

I have the same issue and I have tried using nodeRef according to the sample code at https://stackoverflow.com/questions/63603902/finddomnode-is-deprecated-in-strictmode-finddomnode-was-passed-an-instance-of-d. After updating the code using nodeRef, when I drag my component, it shakes terribly! When I use handle prop instead of nodeRef, the component can be dragged smoothly. I tested this with the latest version of Chrome, Edge and Firefox. The terrible shaking happens with all browsers.

So, if using nodeRef is the only solution, this library is not good for me and I have to find another drag & drop library. To be fair, my component is rather very complex and it's also resizable. If the component is simple, the nodeRef workaround would work just fine.

fujiokae avatar Sep 04 '24 21:09 fujiokae

@fujiokae did you find a good alternative that works well with resizable?

designoor avatar Oct 12 '24 10:10 designoor

There is another component where I implement sortable elements with dnd-kit (https://dndkit.com/). This component is not resizable, though. But at least dnd-kit does not have the "findDOMNode is deprecated" issue. I will try dnd-kit for my draggable & resizable component later.

fujiokae avatar Oct 14 '24 16:10 fujiokae

same error,but i fixed it by this

import React from 'react'; import { DraggableCore } from 'react-draggable';

class MyComponent extends React.Component { constructor(props) { super(props); this.draggableRef = React.createRef(); // 创建一个 ref }

componentDidMount() { const domNode = this.draggableRef.current; // 直接使用 ref 获取 DOM 节点 // 对 domNode 进行操作 }

render() { return ( <DraggableCore>

拖动我
{/* 将 ref 添加到元素上 */} </DraggableCore> ); } }

ljmongo avatar Oct 16 '24 09:10 ljmongo

After updating the code using nodeRef, when I drag my component, it shakes terribly!

terrible shake is solved by adding offsetParent={document.body} to Draggable, no idea why, but I've found it here:

https://github.com/react-grid-layout/react-draggable/issues/761#issuecomment-2434139085

rlidwka avatar Nov 09 '24 14:11 rlidwka

After updating the code using nodeRef, when I drag my component, it shakes terribly!

terrible shake is solved by adding offsetParent={document.body} to Draggable, no idea why, but I've found it here:

#761 (comment)

wow, it saved my day, LOL

tunglt1810 avatar Nov 28 '24 16:11 tunglt1810

使用 nodeRef 代替 findDOMNode react-draggable 提供了 nodeRef 作为替代方案,代码修改如下

import React, { useRef } from "react";
import Draggable from "react-draggable";

const MyComponent = () => {
  const nodeRef = useRef(null);

  return (
    <Draggable nodeRef={nodeRef}>
      <div ref={nodeRef} className="draggable-box">
        拖拽我!
      </div>
    </Draggable>
  );
};
export default MyComponent;

这里的 nodeRef 直接绑定到了 div 上,避免 findDOMNode 触发的警告。

CristinaSong avatar Mar 19 '25 07:03 CristinaSong

Yes, adding offsetParent={document.body} to <Draggable> solved my problem, as well! Thanks!!

fujiokae avatar Apr 07 '25 20:04 fujiokae