Skip to content

Instantly share code, notes, and snippets.

@wuzzeb
Created September 29, 2019 18:07
Show Gist options
  • Save wuzzeb/b15b4897dfa5590b344f60f52a97d285 to your computer and use it in GitHub Desktop.
Save wuzzeb/b15b4897dfa5590b344f60f52a97d285 to your computer and use it in GitHub Desktop.
Typescript redux store definition
import { createStore } from "./typed-redux";
import { compose, applyMiddleware } from "redux";
export { SampleState, SampleAction, SampleActionType } from "./sample";
import { sampleReducer } from "./sample";
/* tslint:disable */
const composeEnhancers =
typeof window === "object" && (window as any)["__REDUX_DEVTOOLS_EXTENSION_COMPOSE__"]
? (window as any)["__REDUX_DEVTOOLS_EXTENSION_COMPOSE__"]
: compose;
/* tslint:enable */
const store = createStore(
{
sample: sampleReducer
//foo: fooReducer,
//bar: barReducer
},
m => m, //middleware, none in this example
m => composeEnhancers(applyMiddleware(m)) //enhancer
);
export const useSelector = store.useSelector;
export const useDispatch = store.useDispatch;
export const Provider = store.Provider;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment