Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import app component to render
- import App from './components/App';
- import ReactDOM from 'react-dom';
- import React from 'react';
- // redux utilities
- // create a stpre, apply middlewares to it
- import { createStore, applyMiddleware } from 'redux';
- // store provider
- import {Provider} from 'react-redux';
- // middleware to parse actions' promises
- import { promiseMiddleware } from './middleware';
- // defaultstate + trivial reducer
- const defaultState = {
- appName: 'conduit',
- articles: null,
- };
- const reducer = function(state = defaultState, action) {
- // update state based on the action type
- switch (action.type) {
- // HOME_PAGE_LOADED => put articles into state
- case 'HOME_PAGE_LOADED':
- return { ...state, articles: action.payload.articles };
- // unrecognized action type => don't change state
- default:
- return state;
- }
- };
- // create store
- const store = createStore(reducer, applyMiddleware(promiseMiddleware));
- // wrap app with provider, render it in root element
- ReactDOM.render(
- <Provider store={store}>
- <App />
- </Provider>,
- document.getElementById('root')
- );
Advertisement
Add Comment
Please, Sign In to add comment