【问题标题】:Unable to use material-ui withStyles() with react-beautiful-dnd无法将 Material-ui withStyles() 与 react-beautiful-dnd 一起使用
【发布时间】:2018-08-21 16:43:04
【问题描述】:

我能够在sandbox 中重现错误。 这些是我看到的错误:

本地:

Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.

Check the render method of `WithStyles(Card)`.
    in Card (created by WithStyles(Card))
    in WithStyles(Card) (at Todo.js:112)

本地和Sandbox:

Invariant failed: Cannot get draggable ref from drag handle

从我的谷歌搜索来看,我似乎不能使用withStyles,因为它是一个无状态的功能组件。如果是这种情况,有什么替代方案?我想继续使用 withStyle 包装器的好处(它将 mui 主题和样式表注入到组件中)。

请注意,为了清楚起见,我简化了沙箱代码(例如,我删除了 redux)。

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    解决方案是将Card 组件包装在div 中。这是sandbox with a working solution

    【讨论】:

    • 非常适合将 Material UI 组件包装在 div 中
    猜你喜欢
    • 2020-06-30
    • 1970-01-01
    • 2020-08-22
    • 2021-05-25
    • 1970-01-01
    • 2018-04-11
    • 2022-12-29
    • 2017-10-26
    • 1970-01-01
    相关资源
    最近更新 更多