Skip to content

Instantly share code, notes, and snippets.

@ryanjyost
Created January 19, 2018 04:53
Show Gist options
  • Select an option

  • Save ryanjyost/52c5d23e308796a4c292beb9212e8a9d to your computer and use it in GitHub Desktop.

Select an option

Save ryanjyost/52c5d23e308796a4c292beb9212e8a9d to your computer and use it in GitHub Desktop.
The index.js for Dog Saga - Redux-Saga Beginner Tutorial
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import registerServiceWorker from "./registerServiceWorker";
import { createStore, applyMiddleware, compose } from "redux";
import createSagaMiddleware from "redux-saga";
import { Provider } from "react-redux";
import { reducer } from "./redux";
import { watcherSaga } from "./sagas";
// create the saga middleware
const sagaMiddleware = createSagaMiddleware();
// dev tools middleware
const reduxDevTools =
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__();
// create a redux store with our reducer above and middleware
let store = createStore(
reducer,
compose(applyMiddleware(sagaMiddleware), reduxDevTools)
);
// run the saga
sagaMiddleware.run(watcherSaga);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
registerServiceWorker();
@zhang1605
Copy link
Copy Markdown

According to official doc, Advanced store setup should be as followed:

import { createStore, applyMiddleware, compose } from "redux";

// redux dev-tool enhancer
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

// redux store
let store = createStore(
  reducer,
  composeEnhancers(applyMiddleware(sagaMiddleware))
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment