import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/app';
ReactDOM.render( <App />, document.getElementById("app") );
import React from 'react';
import { combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux';
import { BrowserRouter, Route, Switch, Link } from 'react-router-dom';
import Header from './header';
import Footer from './footer';
import Home from './home';
import About from './about';
import NotFound from './not-found';
import EDElements from './e-d-elements';
import ActionsReducers from './actions-reducers';
import menReducers from './../reducers/men';
import animalsReducers from './../reducers/animals';
let store = createStore( combineReducers( { menReducers, animalsReducers } ) );
// unsubscribe = store.subscribe( () => console.log( store.getState() ) );
export default (props) => (
<div>
<Provider store={store}>
<BrowserRouter>
<div>
<Header/>
<div className="content">
<div className='pure-g'>
<div className="pure-u-1-5">
<nav>
<ul>
<li><Link to="/e-d-elements">Включение и выключение элементов</Link></li>
<li><Link to="/actions-reducers">События и редьюсеры</Link></li>
</ul>
</nav>
</div>
<div className="pure-u-4-5">
<Switch>
<Route exact path='/' component={ Home } />
<Route path='/about' component={ About } />
<Route path='/e-d-elements' component={ EDElements } />
<Route path='/actions-reducers' component={ ActionsReducers } />
<Route component={ NotFound } />
</Switch>
</div>
</div>
</div>
<Footer/>
</div>
</BrowserRouter>
</Provider>
</div>
);
import React from 'react';
import { add as addMan } from './../actions/men';
import { add as addAnimal } from './../actions/animals';
export default class ActionsReducers extends React.Component {
constructor() {
super();
console.log( store );
// store.dispatch(
//
// addMan( [
// { name: 'Альберт', family: 'Эйнштейн' },
// { name: 'Мария', family: 'Кюри' },
// { name: 'Томас', family: 'Эдисон' } ]
// )
//
// );
// store.dispatch(
//
// addAnimal( [
// { name: 'Лиса' },
// { name: 'Медведь', },
// { name: 'Волк' } ]
// )
//
// );
}
getMoreAnimals() {
// store.dispatch(
//
// addAnimal( [
// { name: 'Енот' },
// { name: 'Лось', },
// { name: 'Рысь' } ]
// )
//
// );
}
render() {
// let currentState = store.getState();
// { currentState.animalsReducers.animalsApp.map( function( animal ) { return animal.name + ', ' } ) }
return (
<div>
<main>
<h1>Действия и редьюсеры</h1>
<div>
<div className='pure-g'>
<div className="pure-u-1-2">
<h2>Люди</h2>
</div>
<div className="pure-u-1-2">
<h2>Животные</h2>
<button onClick={this.getMoreAnimals}>Еще</button>
</div>
</div>
</div>
</main>
</div>
);
}
}
const mapStateToProps = state => ({
userData: state.userData,
});
import { createSelector } from 'reselect';
export const userDataSeleror = state => state.userData;
export const userSelector = state => createSelector(
userDataSelector,
userData => userData.user,
);
export const isUserDataLoadingSelector = state => createSelector(
userDataSelector,
userData => userData.isLoading,
);
export const isUserDataErrorSelector = state => createSelector(
userDataSelector,
userData => userData.isError,
);
import { fetchUserData } from './somePlace';
import Profile from './Profile';
import {
userSelector,
isUserDataLoadingSelector,
isUserDataErrorSelector,
} from './selectors';
const mapStateToProps = state => ({
user: userSelector(state),
isLoading: isUserDataLoadingSelector(state),
isError: isUserDataErrorSelector(state),
});
const mapDispatchToProps = {
fetchUserData,
};
export default connect(mapStateToProps, mapDispatchToProps)(Profile);
class Profile extends Component {
componentDidMount() {
this.props.fetchUserData();
}
render() {
const { user, isLoading, isError } = this.props;
return (
...
);
}
}