私はreactを使ってコードを書いていますが、私はreduxを使い始めました(ソートのコンテナが必要なので)。しかし、私はちょっとしたために1つの場所で立ち往生しています。
は、私はこのエラーを取得 -どちらのコンテキストまたは小道具にもストアが見つかりませんでした
不変違反:コンテキストまたは「接続(ホームページ)」の 小道具のいずれかで「ストア」を見つけることができませんでした。 にルートコンポーネントをラップするか、明示的に「ストア」を 「支店(ホームページ)」の小道具として渡します。
私はグーグルで試した、と反応する-再来のtroubleshooting sectionによると、これは、これらの3つの事で確認することができます。
1.あなたがページ上で反応の複製インスタンスを持っていないことを確認してください。
2.プロバイダの<にルートコンポーネントをラップすることを忘れないでください。
3. ReactとReact Reduxの最新バージョンを実行していることを確認してください。
Iは、(ストアはプロバイダに定義されている)ルートであり、次のコードがある -
import React from 'react';
import { Router, browserHistory } from 'react-router';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import reduxThunk from 'redux-thunk';
import routes from '../Routes';
import reducers from './reducers/reducers';
import actions from './actions/actions';
export default class AppRoutes extends React.Component {
render() {
const store = createStore(reducers, applyMiddleware(reduxThunk));
return (
<Provider store={store}>
<Router history={browserHistory} routes={routes} onUpdate={() => window.scrollTo(0, 0)}/>
</Provider>
);
}
}
を、このエラーが唯一の私が持っている二つの成分のいずれかで発生 -
// No error when connected only in this component
import React from 'react';
import { connect } from 'react-redux';
import * as actions from './actions/actions';
class Dashboard extends React.Component {
constructor(props) {
super(props);
}
render() {
return <h1>Hello, {this.props.isAuthenticated.toString()}</h1>;
}
}
function mapStateToProps(state) {
return {
content: state.auth.content,
isAuthenticated: state.auth.authenticated
};
}
export default connect(mapStateToProps, actions)(Dashboard);
// Error thrown when I try to connect this component
import React from 'react';
import LoginPage from './LoginPage';
import Dashboard from './Dashboard';
import Loading from './Loading';
import { connect } from 'react-redux';
import * as actions from './actions/actions';
class HomePage extends React.Component {
constructor(props) {
super(props);
this.setState({
loading: true
});
}
render() {
var inPage = undefined;
if(this.props.isAuthenticated) {
console.log('Logged in');
inPage = <Dashboard user = {HomePage.user}/>;
}
else if (this.state.loading){
console.log('Loading');
inPage = <Loading />;
}
else {
console.log('Login');
inPage = <LoginPage />;
}
return (
<div>
{inPage}
</div>
);
}
}
function mapStateToProps(state) {
this.setState({
loading: false
});
return {
content: state.auth.content,
isAuthenticated: state.auth.authenticated
}
}
export default connect(mapStateToProps, actions)(HomePage);
は、私はあなたがmapStateToPropsでSETSTATEを行う必要はないと思う、あなたはその時点で反応するコンポーネントのコンテキストではありません。また、私はあなたのAppRoutesコンポーネントが間違っていると思います、私は通常、ストアとコンポーネント/ルート宣言のすべてのredux関連の変数を作成します。 –
@JeremyD setStateを削除しました。あなたが話している設定に切り替えました。しかし、それはまだ起こっている。私の一日を食べて、これをどうやって稼働させるかを考えている。 – Zeokav