有什么方法可以解决这个错误,即每次单击 mui 数据表时,在 StrictMode 中都不推荐使用 findDOMNode 吗?

问题描述

这就是每次我单击 muidatatable 时错误所说的内容。有什么办法可以解决这个问题吗?如果不修复,会不会在我以后部署项目时造成一些问题?

index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode. Instead,add a ref directly to the element you want to reference. Learn more about using refs safely here:

这是我的代码

import React,{Component} from 'react';
import MUIDataTable from "mui-datatables";
import {firestore} from './../../../firebase/firebase.utils';

class UserTable extends Component {
    constructor() {
        super();
        this.state = { users: []};
      }

    columns = ["display Name","Email","Address"];
    options = {
        filter: true,selectableRows: 'none',};
  

    componentDidMount() {
        firestore.collection('users')
            .get()
            .then( snapshot => {
                const users = []
                 snapshot.forEach(doc => {
                    const data = doc.data()
                    users.push({"display Name":data.displayName,'Email': data.email,'Address' : data.address});
                })
                this.setState({ users : users})
                // console.log(snapshot)
            })
        .catch(error => console.log(error))
    }   

    render() {
        return this.state.users ? (
            <MUIDataTable
              title={"List of Users"}
              columns={this.columns}
              data={this.state.users}
              options={this.options}
            />
          ) : (
            <div>Loading...</div>
          );
        }
      }
 
export default UserTable;

解决方法

为了修复此错误,您必须将@material-ui/core 更新到 v5 或删除 StrictMode。 Github issue