This warning message is indicating that the usage of the findDOMNode function is deprecated in React's StrictMode.

In React, findDOMNode is a method that allows you to access the underlying DOM node of a React component. However, it has been deprecated because it can lead to potential issues and can be a source of bugs.

The warning suggests that instead of using findDOMNode, you should add a ref directly to the element you want to reference.

Here's an example of how you can use refs to reference an element in React:

import React, { useRef } from "react";

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

  const handleClick = () => {
    // Access the underlying DOM node using the ref
    const myElement = myElementRef.current;
    // Do something with the element
    console.log(myElement);
  };

  return (
    <div>
      {/* Add the ref to the element you want to reference */}
      <span ref={myElementRef}>Hello World</span>
      <button onClick={handleClick}>Click me</button>
    </div>
  );
};

export default MyComponent;

In this example, a ref (myElementRef) is created using the useRef hook. The ref is then added to the <span> element. When the button is clicked, the handleClick function can access the underlying DOM node using the ref (myElementRef.current).

By following this approach, you can safely reference elements without relying on the deprecated findDOMNode function

Warning findDOMNode is deprecated in StrictMode findDOMNode was passed an instance of Wrapper which is inside StrictMode Instead add a ref directly to the element you want to reference Learn more abou

原文地址: https://www.cveoy.top/t/topic/h9cM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录