我收到以下错误: “TypeError: Cannot read property 'styleKeeperContext' of undefined”,当我尝试将悬停伪类添加到我正在使用 Radium 插件设置样式的按钮时
我试图排除 Radium 导入以查看 Rootstyle 属性是否仍然有效并且确实如此。每当我添加 Radium 导入和导出由 Radium 函数封装的应用程序组件时就会出现问题
我的假设是我在使用 hover 伪类或其他方面做的不正确,我不理解术语“styleKeeperContext”
我怎样才能摆脱这个错误并仍然使用插件,同时将样式限制在我的组件范围内
以下代码截图
最佳答案
当我将 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.
}
关于ReactJs 在使用 Radium 插件时出现未定义错误的 styleKeeperContext',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59496626/