{ const Compo-6ren">
gpt4 book ai didi

javascript - 未捕获 [不变违规 : Could not find "store" in either the context or props

转载 作者:行者123 更新时间:2023-11-30 06:22:09 24 4
gpt4 key购买 nike

基本上我将 componentB 导入 componentA

componentA 中,我基本上是在做类似的事情

const ComponentA = () => {
const ComponentB = blah.map(() => {

})
//more stuff
return(
<div> stuff here </div>
)
}

但是当我为 ComponentA 文件运行测试(已经构建)时,它们会出现该错误消息

两个组件都正确连接到商店:

导出默认连接(mapStateToProps)(ComponentA)

导出默认连接(mapStateToProps,mapDispatchToProps)(ComponentB)

什么会导致该错误?

我知道之前我不得不以不同的方式导入它。目前我只是像这样导入它:import componentB from '/components'

但我确实尝试了 import { componentB } from '/components' 所以只是通过传递商店导出组件但是它不起作用因为它来自商店未连接

有什么想法吗?

最佳答案

当您测试 redux 连接组件时,您需要使用假存储或内存存储来呈现它们。通常最好的做法是将未连接的组件呈现为 import {component} from '...'; 然后传递组件期望的 Prop 。 redux 库已经有测试用例,因此没有必要重复这项工作。

关于javascript - 未捕获 [不变违规 : Could not find "store" in either the context or props,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com