Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么组件未连接到redux存储?_Redux_React Redux_React Router - Fatal编程技术网

为什么组件未连接到redux存储?

为什么组件未连接到redux存储?,redux,react-redux,react-router,Redux,React Redux,React Router,我正在尝试将一些组件(用户)连接到我的应用商店。我会告诉你每一步 首先,我在index.js中创建了我的存储: // composeWithDevTools helps to follow state changes, remove in production const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; const sagaMiddleware = createSagaMiddl

我正在尝试将一些组件(用户)连接到我的应用商店。我会告诉你每一步

首先,我在index.js中创建了我的存储:

// composeWithDevTools helps to follow state changes, remove in production
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const sagaMiddleware = createSagaMiddleware();

const store = createStore(reducers, composeEnhancers(applyMiddleware(sagaMiddleware)));
//sagaMiddleware.run(usersSaga);
console.log('MYSTORE: ', store);

ReactDOM.render(
    <Provider store={store}>
        <App />
    </Provider>,
    document.getElementById('root'),
);
现在,我的App.js文件如下所示:

import React from 'react';
import { HashRouter, Route, Redirect } from 'react-router-dom';
import { AuthorisationMails } from './route-components/AuthorisationMails.js';
import { ChangePassword } from './route-components/ChangePassword.js';
import { Credits } from './route-components/Credits.js';
import { Graphs } from './route-components/Graphs.js';
import { Groups } from './route-components/Groups.js';
import { HeaderBar } from './components/HeaderBar.js';
import { Home } from './route-components/Home.js';
import { Login } from './route-components/Login.js';
import { MailServers } from './route-components/MailServers.js';
import { MailStatus } from './route-components/MailStatus.js';
import { Options } from './route-components/Options.js';
import { StatusMails } from './route-components/StatusMails.js';
import { Users } from './route-components/Users.js';

const App = () => (
    <div>
        <HashRouter>
            <HeaderBar />
            <Route path="/">
                <Redirect to="/login" />
            </Route>
            <Route path="/login" component={Login} />
            <Route path="/dashboard_user" component={Users} />
        </HashRouter>
    </div>
);

export default App;
从“React”导入React;
从“react router dom”导入{HashRouter,Route,Redirect};
从“./route components/authorizationmails.js”导入{authorizationmails};
从“./route components/ChangePassword.js”导入{ChangePassword};
从“./route components/Credits.js”导入{Credits};
从“./route components/Graphs.js”导入{Graphs};
从“./route components/Groups.js”导入{Groups};
从'./components/HeaderBar.js'导入{HeaderBar};
从“./route components/Home.js”导入{Home};
从“./route components/Login.js”导入{Login};
从“./route components/MailServers.js”导入{MailServers};
从“./route components/MailStatus.js”导入{MailStatus};
从“./route components/Options.js”导入{Options};
从“./route components/StatusMails.js”导入{StatusMails};
从“./route components/Users.js”导入{Users};
常量应用=()=>(
);
导出默认应用程序;
在用户中,我尝试使用mapstateToProps连接到商店,并按照您在此处看到的方式进行连接:

import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import * as actions from '../redux/actions';

export class Users extends Component {
    componentDidMount() {
        console.log('USERPROPS: ', this.props);
    }
    render() {
        return <div>Users</div>;
    }
}

const mapStateToProps = state => {
    console.log('USERSSTATE: ', state.user);
    return {
        users: state.userReducer,
    };
};

export default withRouter(connect(mapStateToProps)(Users));
import React,{Component}来自'React';
从“react router dom”导入{withRouter};
从'react redux'导入{connect};
从“../redux/actions”导入*作为操作;
导出类用户扩展组件{
componentDidMount(){
log('USERPROPS:',this.props);
}
render(){
返回用户;
}
}
常量mapStateToProps=状态=>{
log('USERSSTATE:',state.user);
返回{
用户:state.userReducer,
};
};
使用路由器导出默认值(连接(MapStateTops)(用户));
这里的问题是,由于USERPROPS的console.log不包含属性user,因此我以错误的方式连接。它包含历史位置和匹配

我尝试使用以下url进行连接


你知道我的组件为什么没有连接到商店吗?

我想你可能需要使用state.users.user:

const mapStateToProps = state => {
    return {
        users: state.users.user,
    };
};

解决了这个问题,我在导入组件时删除了括号,例如:


从“./route components/Credits.js'=>从“./route components/Credits.js'

导入{Credits}这不会有任何区别,因为我仍然会在属性的console.log中看到userReducer。您的console.log state.user在mapStateToProps中是否为null?尝试记录state.userreduceries我正在console.log中映射state.user,但它甚至没有打印:``const-mapStateToProps=state=>{console.log('USERSSTATE:',state.userReducer');返回{users:state.userReducer.user,};}```Try console.log('USERSSTATE:',state.users.user);userReducer在CombineReducer步骤中重命名为users。或者从console.log('USERSSTATE:',state.users)开始;看看这个workstreid是否也存在,如果这些变量存在,console语句应该返回null,这样看起来它甚至没有到达那里。
const mapStateToProps = state => {
    return {
        users: state.users.user,
    };
};