H
H
hollanditkzn2018-01-28 18:12:45
React
hollanditkzn, 2018-01-28 18:12:45

How to get value from store via react-router?

I do n't understand how to get value through routers
My index.js code

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import  { Provider } from 'react-redux';
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
import { Route, Switch, Redirect } from 'react-router';
import { BrowserRouter } from 'react-router-dom';
import thunk from 'redux-thunk';
import loginReducer from './redux/login/loginReducer';
import AuthProvider from './containers/AuthProvider';
import Home from "./component/Home";
import Auth from "./AuthForm";
import { WithHelmet, withHelmet } from './utils/WithHelmet';

const rootReducer = combineReducers({
    login: loginReducer,
});

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, composeEnhancers(
    applyMiddleware(thunk)
));

ReactDOM.render(
        <div>
          <Provider store={store}>
            <BrowserRouter>
              <AuthProvider authComponent={withHelmet({ title: 'Авторизация'})(Auth)}>
                <Route path='/' strict>
                  <WithHelmet title='Главная страница'>
                    <Home />
                  </WithHelmet>
                </Route>
              </AuthProvider>
            </BrowserRouter>
          </Provider>
        </div>,
    document.getElementById('content')
);

component/Home.js
import React, {Component} from 'react';
import Header from './Header';
import { connect } from 'react-redux';

class Home extends Component{
    render(){
        const { user } = this.props;
        return(
            <div>
                <Header/>
                <h1>Добро пожаловать</h1>
                <div>ФИО: {user}</div>
                <div>Должность: </div>
            </div>
        );
    }
}
const mapStateToProps = state => {
    user: state.login.user
};

export default connect(mapStateToProps)(Home);

Here in state.login.user there is the data {id: 1, login: "admin", name: "Ivan Ivanovich"}
But how can I translate const { user } = this.props;it, because the dispatcher is empty there.
Immediately I say that I am a beginner and I don’t stick a little how I should get these values ​​​​in the component
Here is the full code on the github if anything https://github.com/hollandit/trainingPortal/tree/m...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hollanditkzn, 2018-01-29
@hollanditkzn

сonst mapStateToProps = state => ({
    user: state.login.user,
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question