我在 ASP.NET Core 应用程序中使用 react/redux,如果我不包含 redux 一切都会很顺利,但是在添加 redux 并更改当前组件以连接到商店后,我在浏览器中出现以下错误(发布网站后 t wwwroot 文件夹):
ReferenceError: Provider is not defined
或
ReferenceError: connect is not defined
...
请注意,在我的 wwwwroot 文件夹中,我添加了 react-redux.js 文件,该文件存在于节点模块中 react-redux 模块的 dist 文件夹中。
---node_modules\react-redux\dist\react-redux.js----
在下面,我将其中一个容器的代码放在浏览器中,该代码在运行时向我显示错误:
declare var { connect }: typeof import("react-redux");
import { addTodo } from '../redux/actions/todo-actions.js';
import AddTodoForm from '../components/AddTodoForm.js';
const mapDispatchToProps = {
handleSubmit: addTodo
};
export default connect<any, any, any>(null, mapDispatchToProps)(AddTodoForm)
在我看来,我添加到 wwwroot 文件夹的 reaxt-redux.js 没有正确地将其接口(interface)(特别是连接接口(interface))导出到窗口中!
考虑到我的服务器上没有节点模块和 npm,所以我更喜欢在我的页面中手动引用 react、redux 和 react-redux javascript 文件。
你能告诉我我做错了什么吗?
提前致谢
最佳答案
我发现了问题。当我使用 Webpack 时,因为我在页面上有多个组件,redux 商店被捆绑并添加了不止一次。需要更改 store.tsx 以防止它。
关于javascript - 将 react-redux 与 ASP.NET Core 一起使用时在运行时出现未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52982029/