我正在使用mui-datatables,但发现它与功能组件(Material UI v4)不兼容,但是我发现Forwarding Refs应该可以解决我的问题,我遵循了它,但我想我做错了什么。

// TablesList.js
const useStyles = makeStyles(theme => ({
    toolbar: theme.mixins.toolbar,
    content: theme.styles.content,
}));

const TableList = React.forwardRef((props, ref) => {
    const classes = useStyles();
    const columns = ["Name", "Company", "City", "State"];
    const options = {
        filterType: 'textField',
        rowsPerPage: 50,
        rowsPerPageOptions: [10, 50, 100]
    };

    const data = [
        ["Joe James", "Test Corp", "Yonkers", "NY"],
        ["John Walsh", "Test Corp", "Hartford", "CT"],
        ["Bob Herm", "Test Corp", "Tampa", "FL"],
        ["James Houston", "Test Corp", "Dallas", "TX"],
    ];
    return (
        <main className={classes.content}>
            <div className={classes.toolbar}/>
            <MUIDataTable
                ref={ref} // Passing ref
                title={"Employee List"}
                data={data}
                columns={columns}
                options={options}
            />
        </main>
    )
});


我在Route中调用此组件:

<Route exact path="/" component={TablesList} ref={ref}/>


那我在做什么错呢?因为我仍然在控制台中看到错误。

最佳答案

不幸的是,还不支持Material UI 4。 GitHub上还有一张公开票:(请参见https://github.com/gregnb/mui-datatables/issues/595

08-07 18:22