gpt4 book ai didi

javascript - Redux 升级导致不变性违规

转载 作者:行者123 更新时间:2023-12-03 00:33:51 24 4
gpt4 key购买 nike

我在 this codesandbox 中收到不变违规错误:

Invariant Violation Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of Provider.

This codesandbox工作没有任何问题。它完全相同,只是它不使用 redux 6.0 和 connected-react-router,而是使用 redux 5.0.6 和 react-router-redux

此升级可能出了什么问题,或者我正在执行的其他操作导致了此错误?谢谢!您还可以在下面看到一些代码示例。

index.js

import React from "react";
import { render } from "react-dom";
import { Provider } from "react-redux";
import { ConnectedRouter } from "connected-react-router";
import { fetchStuff } from "./actions/index";
import App from "./components/app";
import { store, history } from "./store";

store.dispatch(fetchStuff);

render(
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>,
document.getElementById("container")
);

App.js:

import React from "react";
import { connect } from "react-redux";

const App = ({ data }) => (
<div>{data.length > 0 ? <h1>Completed</h1> : <h1>Loading</h1>}</div>
);

const mapStateToProps = state => ({
data: state.data.data
});

export default connect(mapStateToProps)(App);

最佳答案

在您的codesandbox中,reactreact-dom都有不同的版本,您需要使用相同版本的react和react -dom 在你的项目中。在您的codesandbox中将react-dom升级到16.4.0并且它可以工作

Working Codesandbox

关于javascript - Redux 升级导致不变性违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53736071/

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