【问题标题】:ReactJs Getting a styleKeeperContext' of undefined error when using Radium pluginReactJs在使用Radium插件时获取未定义错误的styleKeeperContext'
【发布时间】:2020-04-17 04:20:00
【问题描述】:

我收到以下错误: “TypeError: Cannot read property 'styleKeeperContext' of undefined”,当我尝试将悬停伪类添加到我使用 Radium 插件设置样式的按钮时

我已尝试排除 Radium 导入以查看 Rootstyle 属性是否仍然有效并且确实有效。每当我添加 Radium 导入并导出由 Radium 函数封装的应用程序组件时都会出现问题

我的假设是,我使用悬停伪类的方式或其他方式没有正确执行某些操作,我不理解“styleKeeperContext”一词

我怎样才能摆脱这个错误并仍然使用插件,同时将样式保持在我的组件范围内

以下代码截图

my import statement my import statement

my scoped styles

my Component export error message

【问题讨论】:

    标签: reactjs react-native react-redux react-router


    【解决方案1】:

    当我将this.state 添加到组件时,我开始收到此错误:

    const MyComponent extends Component {
      constructor() {
        super(); // I messed up here
        this.state = { count: 0 };
      }
      // etc.
    }
    

    调用构造函数的时候忘记pass in the component's props to super()了。犯了一个愚蠢的错误,但 Radium 错误使我们很难弄清楚根本原因是什么。

    像这样修复它解决了错误:

    const MyComponent extends Component {
      constructor(props) { // Add props argument
        super(props); // Pass props to super()
        this.state = { count: 0 };
      }
      // etc.
    }
    

    【讨论】:

    • @madnight 没问题! :)
    【解决方案2】:

    我也遇到了同样的问题,在将 Radium 模块版本从 0.26.0 降低到 0.25.2 后问题得到了解决。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 2023-03-23
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    相关资源
    最近更新 更多