App.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import './App.css';
  2. import Layout from "./components/layout.js";
  3. import {Provider, connect} from 'react-redux';
  4. import {Header, Footer, actionCatalogCard, Main} from "./components/index"
  5. import {BrowserRouter as Router, Route, Link, Switch, Redirect} from 'react-router-dom';
  6. import createHistory from "history/createBrowserHistory";
  7. import Catalog from "./components/catalog"
  8. import {createStore, combineReducers, applyMiddleware, compose} from 'redux';
  9. import thunk from 'redux-thunk';
  10. function promiseReducer(state={}, action){
  11. if (action.type === 'PROMISE'){
  12. const { name="default", status, payload, error} = action
  13. if (status){
  14. return {
  15. ...state, [name]: {status, payload: (status === 'PENDING' && state[name] && state[name].payload) || payload, error}
  16. }
  17. }
  18. }
  19. return state;
  20. }
  21. const store = createStore(combineReducers({promiseRed: promiseReducer}), compose(applyMiddleware(thunk)))
  22. function App() {
  23. return (
  24. <>
  25. <Provider store={store}>
  26. <Router history = {createHistory}>
  27. <Header/>
  28. <Main/>
  29. <Footer/>
  30. </Router>
  31. </Provider>
  32. </>
  33. );
  34. }
  35. export default App;