Skip to content

Instantly share code, notes, and snippets.

@anomaly44
Last active February 24, 2017 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anomaly44/83c7d7aa0b92997481f50e25800e6f88 to your computer and use it in GitHub Desktop.
Save anomaly44/83c7d7aa0b92997481f50e25800e6f88 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import App from './App';
import './index.css';
import configureStore from './store';
const store = configureStore({ test: "ok" });
store.dispatch({ type: 'TEST' });
const render = (Component) => {
return ReactDOM.render(
<Provider store={store}>
<Component/>
</Provider>,
document.getElementById('root')
);
};
render(App);
if (module.hot) {
module.hot.accept('./App', () => {
const NextApp = require('./App').default;
ReactDOM.render(
<NextApp/>,
document.getElementById('root')
);
});
}
import { createStore } from 'redux';
const testReducer = (state = [], action) => {
switch (action.type) {
case 'TEST':
return {
...state,
cnt: 0
};
case 'ADD':
return {
...state,
cnt: state.cnt + 1
};
default:
return state;
}
};
export default function configureStore(initialState = {}) {
const store = createStore(
testReducer,
initialState,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
return store;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment