gpt4 book ai didi

redux - 中的错误 - 检查 `Provider` 的渲染方法。 react 还原

转载 作者:行者123 更新时间:2023-12-05 00:11:14 31 4
gpt4 key购买 nike

enter image description here enter image description here

代码:这是我的 index.js 文件

index.js

import { Provider } from "react-redux";
import { createStore } from 'redux';

import App from './app';

import reducer from './store/reducer';

const store = createStore(reducer);
console.log("Store ..."+store);
console.log(Provider);

ReactDOM.render((
<Provider store={store}>
<App/>
</Provider>
), document.getElementById('root'));

代码:这是我的 reducer.js 文件
    reducer.js
import * as actionTypes from './actions';

const initialState = {
assistants:[],
fetchInProgress:true
}

const reducer = (state = initialState, action) =>{

return state;
};

export default reducer;

代码:这是我的 app.js 文件
应用程序.js
class App extends Component{
render(){
return(
<HashRouter>
<Switch>
<Route exact path="/login" name="Login Page" component={Login}/>
<Route exact path="/register" name="Register Page" component=
{Register}/>
<Route exact path="/404" name="Page 404" component={Page404}/>
<Route exact path="/500" name="Page 500" component={Page500}/>
<Route path="/" name="Home" component={Full}/>
</Switch>
</HashRouter>
);
}
}

export default App;

错误: Uncaught Error :元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:对象。

查看 Provider的渲染方法.

请引用这两个图像的错误。我收到错误,因为请检查您的提供程序组件渲染方法,但这不是我可以更改提供程序渲染方法。因为它是从 redux 导入的类,所以请帮助我解决这个问题,我在过去两天面临这个问题无法解决。

最佳答案

与以前的代码和新的 React 或 Redux 版本不兼容。
在我降级安装的工具之前,我遇到了这个问题,请参阅比较的 package.json 文件的附加图像。
enter image description here
我不知道哪个文件是罪魁祸首。
屏幕右侧的阵容可以正常工作,而另一个则无论我做什么都会出错。
版本差异以黄色背景突出显示。
我猜(未测试)这个问题源于 react 和 react-dom 包之间的版本差异。

Victor Nunes 建议的解决方案是:

  • 删除 package-lock.json文件和 node_modules文件夹
  • 删除 package.json 上“依赖项”的所有内容
  • 运行 npm install --save react react-dom react-redux react-scripts redux

  • 除了上面列出的软件包之外,您可能还需要安装其他软件包。

    关于redux - <Provider> 中的错误 - 检查 `Provider` 的渲染方法。 react 还原,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54187538/

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