reactjs - 样式化的组件主题道具在生产中抛出错误但不是开发
问题描述
我有一个 Styled 组件按钮,它可能会或可能不会采用主题道具
${props =>
props.theme &&
props.theme.length > 0 &&
buttonVariant(color.white, color[props.theme], color[props.theme])}
在本地主机上一切都很好,但是在生产中我得到很多类似的错误
Component 'styled.button' (.sc-cHGsZl) references the 'theme' prop in its styles but no theme was provided via prop or <ThemeProvider>.
为什么会这样?
解决方案
尝试使用 ThemeProvider 组件包装您的应用程序。这对我有用,不知道为什么。可能是因为 ThemeProvider 通过 ContextAPI 将主题传递给其他组件,提供了主题。
推荐阅读
- java - 如何使用 Spring Boot 设置自定义登录?
- javascript - React Native StyleSheet.create 异常
- python-3.x - 多个基地在机器人框架中存在实例布局冲突
- bash - 根据条件修改bash命令的功能
- reactjs - 在 React 中全局使用 Socket.IO?
- elasticsearch - ElasticSearch 无法从字符串转换为 ElasticClient.searchRequestparameters
- javascript - 在悬停某些文本时在表格单元格上使用工具提示时出现问题。并且需要被表头固定
- spring-boot - 无法在应用引擎标准环境 (GCP) 中部署预构建映像
- c - 如何连接 LPTSTR 与 char 数组?
- python - 为什么在 Keras 的自定义层中不能使用权重约束和 dropout 函数