Answer the question
In order to leave comments, you need to log in
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')
);
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);
const { user } = this.props;
it, because the dispatcher is empty there. Answer the question
In order to leave comments, you need to log in
сonst mapStateToProps = state => ({
user: state.login.user,
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question