ReactJs 在使用 Radium 插件时出现未定义错误的 styleKeeperContext'

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

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

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

我的假设是我在使用 hover 伪类或其他方面做的不正确,我不理解术语“styleKeeperContext”

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

以下代码截图

my import statement my import statement

my scoped styles

my Component export error message

最佳答案

当我将 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/

相关文章:

android - 键盘打开时 React Native ScrollView 不滚动

javascript - 如何使用扩展语法返回对象并覆盖引用数组的属性

react-native - 当可访问为真时,React Native 找不到子元素

reactjs - 无法读取未定义的属性(读取 'editQuoteModalShown' )react-redux

reactjs - 在浏览器的后退按钮上 react 路由器历史记录

python - 在 React+Django 应用程序中加载图像

reactjs - Jest 报告 componentDidMount 中未调用来自 enzyme 浅层组件的方法

reactjs - react : Which is recommended arrow or normal function?

javascript - 使用 useNavigate 和 state 进行重定向似乎很难完成

javascript - 我收到错误列表中的每个 child 都应该有一个唯一的 "key" Prop