【发布时间】:2019-06-08 19:07:32
【问题描述】:
代码:这是我的 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 文件 app.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;
错误:未捕获的错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。
查看Provider的渲染方法。
请参考两张图片是否有错误。我收到错误,请检查您的提供程序组件渲染方法,但这不是我要更改提供程序渲染方法的。因为它是从 redux 导入的类,所以请帮我解决这个问题,我在过去两天遇到的这个问题无法解决。
【问题讨论】:
-
您的
app.js是否正确导出了您尝试在Provider中渲染的组件? -
你能告诉我们App类和商店吗?
-
我正在为完全相同的问题寻求帮助(也许学习 Max 的相同教程)。我没有组合减速器。
-
请参考图片是否有错误。我在控制台中打印了 Store 和 Provider 值。 i.stack.imgur.com/5AwvS.png
-
我猜你已经升级了 react 版本。你还需要升级 react-dom,它会解决这个问题。
标签: redux react-redux redux-thunk redux-saga react-router-redux