gpt4 book ai didi

javascript - react 错误 : "could not find the ' store' in the context of . ..”

转载 作者:行者123 更新时间:2023-11-29 23:01:55 26 4
gpt4 key购买 nike

我在运行我的 React 应用程序时收到此错误消息:

Could not find "store" in the context of "Connect(Booklist)". Either wrap the root component in a , or pass a custom React context provider to and the corresponding React context consumer to Connect(Booklist) in connect options.

我正在使用 Create React App 并尝试创建一个列出一些详细信息的应用。

见下面的代码:

app.js

import React, { Component } from 'react';
import './App.css';
import Booklist from './container/book-list';

class App extends Component {
render() {
return (
<div className="App">
<Booklist />
</div>
);
}
}

export default App;

book-list.js

import React, {Component} from 'react';
import { connect } from 'react-redux';

class Booklist extends Component{
renderList(){
return this.props.books.map((book) =>{
return(
<li key={book.title}>{book.title}</li>
);
}
);
}
render(){
return this.props.books.map((book) =>{
return(
<ul>{this.renderList()}</ul>
);
}
);
}
}
function mapStateToProps(state){
return {
books: state.books
}
}
export default connect (mapStateToProps)(Booklist);

books_reducer.js

export default function(){
return[
{title: booke1},
{title: booke2},
{title: booke3},
{title: booke3}
]
}

reducer 中的 index.js

import {combineReducers} from redux;
import booksReducer from './books_reducer'
const rootReducer = combineReducers({
books: booksReducer
});

export default booksReducer;

最佳答案

您是否在商店中包装您的应用程序?

import { Provider } from 'react-redux';
const store = createStore(
combineReducers({
books: booksReducer
});
)
<Provider store={store}>
<App />
</Provider>

关于javascript - react 错误 : "could not find the ' store' in the context of . ..”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55428185/

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