在 StrictMode 中不推荐使用 findDOMNode

sam*_*ali 15 reactjs antd

我正在使用 antd 并且看到此错误

findDOMNode 在 StrictMode 中已弃用。findDOMNode 传递了一个 DOMWrap 实例,它在 StrictMode 中。相反,直接向要引用的元素添加 ref

我意识到这是因为mode="horizontal". 我也尝试过使用其他组件,我在 antd 中经常看到这个错误。有没有办法解决这个问题?这是我当前的代码

import React from 'react'
import { connect } from 'react-redux';
import { Layout, Menu  } from 'antd';

const { Header, Footer, Content } = Layout;

  const AddForm = () => {
    return (
    <div>
        {/* // Menu Starts from here */}

        <Layout className="layout">
            <Header>
            <div className="logo" />
            <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
                <Menu.Item key="1">nav 1</Menu.Item>
                <Menu.Item key="2">nav 2</Menu.Item>
                <Menu.Item key="3">nav 3</Menu.Item>
            </Menu>
            </Header>
            <Content style={{ padding: '0 50px' }}>
            <div className="site-layout-content">Content</div>
            </Content>
            <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
        </Layout>
    </div>
    )

  };
Run Code Online (Sandbox Code Playgroud)

小智 -1

findDOMNodeReact 16 中没有好的替代方案: https://github.com/ant-design/ant-design/issues/22493