Advertisement
Guest User

react-redux-problem

a guest
Aug 29th, 2017
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //index.js
  2. // Render the main component into the dom
  3. ReactDOM.render(
  4.     <Provider store={store}>
  5.         <BrowserRouter>
  6.             <div>
  7.                 {routes.rules.map((route, i) => (
  8.                     <Rules key={i} {...route}/>
  9.                 ))}
  10.             </div>
  11.         </BrowserRouter>
  12.     </Provider>
  13.     , document.getElementById('app'));
  14.  
  15.  
  16. //routes.js
  17. exports.rules = [
  18.     {
  19.         path: '/',
  20.         component: MainContainer
  21.     },
  22.     {
  23.         path: '/app',
  24.         component: AppContainer
  25.     },
  26.     {
  27.         path: '/event/:id',
  28.         component: EventContainer
  29.     },
  30.     {
  31.         path: '/event/:id/join',
  32.         component: EventJoinContainer
  33.     }
  34.  
  35. ];
  36.  
  37. ////Redux store
  38. import {connect} from 'react-redux';
  39. import {mapDispatchToProps, mapStateToProps} from '../sources/app';
  40.  
  41. @connect(mapStateToProps, mapDispatchToProps)
  42. class SampleClass {}
  43.  
  44.  
  45. //app.js
  46. export function mapStateToProps(state) {
  47.     return {
  48.         ...state
  49.     };
  50. }
  51.  
  52. export function mapDispatchToProps(dispatch) {
  53.     const creators = Map()
  54.         .merge(...actions)
  55.         .filter(value => typeof value === 'function')
  56.         .toObject();
  57.  
  58.     return {
  59.         actions: bindActionCreators(creators, dispatch),
  60.         dispatch
  61.     };
  62. }
  63.  
  64. //actions / reducers
  65. //Exprotuje tablice i ją przekazuje
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement