How to use the redux-thunk.withExtraArgument function in redux-thunk

To help you get started, we’ve selected a few redux-thunk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sharetribe / ftw-daily / src / store.js View on Github external
export default function configureStore(initialState = {}, sdk = null, analyticsHandlers = []) {
  const middlewares = [thunk.withExtraArgument(sdk), analytics.createMiddleware(analyticsHandlers)];

  // Enable Redux Devtools in client side dev mode.
  const composeEnhancers =
    config.dev && typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      : compose;

  const enhancer = composeEnhancers(applyMiddleware(...middlewares));

  const store = createStore(createReducer(), initialState, enhancer);

  return store;
}
github borisding / universsr / src / app / redux / configureStore.js View on Github external
export default function configureStore(preloadedState = {}) {
  const middlewares = [
    // register request actions for dispatch
    // so that it's accessible in respective thunk wrappers
    thunk.withExtraArgument({ ...requestActions }),
    serviceAlert()
  ];

  // check if redux devtools extension compose available
  // apply for development environment only
  const withReduxDevtools =
    isDev &&
    typeof window !== 'undefined' &&
    window.__REDUX_isDevTOOLS_EXTENSION_COMPOSE__;

  // make compose enhancers
  const composeEnhancers = withReduxDevtools
    ? window.__REDUX_isDevTOOLS_EXTENSION_COMPOSE__({
        /* specify extension’s options, if any */
      })
    : compose;
github jsmentor / react-workshops / apps / user-management-app / src / store / configureStore.js View on Github external
export default function configureStore(initialState, helpersConfig) {
  const helpers = createHelpers(helpersConfig);

  const sagaMiddleware = createSagaMiddleware();

  const epicMiddleware = createEpicMiddleware(epics);

  const middlewares = [
    epicMiddleware,
    sagaMiddleware,
    thunk.withExtraArgument(helpers)
    // beforeLoggerMiddleware,
    // afterLoggerMiddleware,
  ];

  let enhancer;

  if (__DEV__) {
    middlewares.push(createLogger());

    // https://github.com/zalmoxisus/redux-devtools-extension#redux-devtools-extension
    let devToolsExtension = f => f;
    if (process.env.BROWSER && window.devToolsExtension) {
      devToolsExtension = window.devToolsExtension();
    }

    enhancer = compose(
github Emurgo / yoroi-mobile / src / helpers / configureStore.js View on Github external
export default () => {
  const logger = {
    log: (message: string, payload: Object) => null,
  }

  const loggerMiddleware = createLogger({
    collapsed: true,
    predicate: (getState, action) => !action.doNotLog,
  })

  const middlewares = [thunk.withExtraArgument({logger})]
  if (process.env.NODE_ENV === 'development') {
    middlewares.push(loggerMiddleware)
  }

  // When not running devtools, use regular compose
  const composeEnhancers =
    (window.__DEV__ && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose

  const store = createStore(
    rootReducer,
    getInitialState(),
    composeEnhancers(applyMiddleware(...middlewares)),
  )

  if (process.env.NODE_ENV === 'development') {
    logger.log = (message: string, payload: Object) =>
github wellyshen / react-cool-starter / src / redux / store.js View on Github external
export default (initialState: Object = {}) => {
  const middlewares = [
    thunk.withExtraArgument(axios),
  ];

  const enhancers = [
    applyMiddleware(...middlewares),
    __DEV__ && typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ?
      window.devToolsExtension() : f => f,
  ];

  const store: Store = createStore(createReducer(), initialState, compose(...enhancers));

  store.asyncReducers = {}; // Async reducer registry

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('./reducers', () => {
      try {
github strues / boldr / src / shared / state / store.js View on Github external
export default function configureStore(history, preloadedState) {
  const reduxRouterMiddleware = routerMiddleware(history);

  const middlewares = [thunk.withExtraArgument(api), reduxRouterMiddleware];

  const enhancers = [
    applyMiddleware(...middlewares),
    IS_DEV &&
      typeof window === 'object' &&
      typeof window.devToolsExtension !== 'undefined'
      ? window.devToolsExtension()
      : f => f,
  ];

  // Creating the store
  const store = createStore(rootReducer, preloadedState, compose(...enhancers));

  /* istanbul ignore next */
  if (module.hot) {
    module.hot.accept('./reducers', () => {
github paularmstrong / react-stateful-firestore / src / index.js View on Github external
export default function init(app: App, userCollection?: string): Promise {
  if (store) {
    throw new Error('Cannot initialize store more than once.');
  }

  const firestore = firebase.firestore(app);
  const auth = firebase.auth(app);

  const thunkArgs = { auth, firestore };
  const middleware = [thunk.withExtraArgument(thunkArgs), batchMiddleware];

  if (process.env.NODE_ENV !== 'production') {
    const createLogger = require('redux-logger').createLogger;
    const logger = createLogger({ collapsed: true, diff: true });
    middleware.push(logger);
  }

  store = createStore(reducers, applyMiddleware(...middleware));
  if (process.env.NODE_ENV !== 'production') {
    window.redux = store;
  }

  const select = initSelect(store);
  const selectAuth = initSelectAuth(auth, userCollection);
  const selectStorage = initSelectStorage(store);
github kenvies / ONE-ReactNative / src / redux / store / configure-store.js View on Github external
/**
 * 创建Store,整合Provider
 *  create by 2017-01-10
 * @flow
 */
import thunk from 'redux-thunk';

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

import _middleware from "../middleware"

import rootReducer from '../reducers/Index';

const _thunk = [thunk.withExtraArgument()];

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, {}, composeEnhancers(
    applyMiddleware(
        ..._middleware.concat(_thunk)
    )
));

export default store;
github usunyu / my-awesome-projects / React / react-ssr / server / src / helpers / createStore.js View on Github external
export default (req) => {
  const axiosInstance = axios.create({
    baseURL: 'http://react-ssr-api.herokuapp.com',
    headers: { cookie: req.get('cookie') || '' },
  });

  const store = createStore(
    reducers,
    {},
    applyMiddleware(thunk.withExtraArgument(axiosInstance)),
  );

  return store;
}
github ETCDEVTeam / emerald-wallet / packages / desktop / src / store / createStore.js View on Github external
export const createStore = (_api) => {
  const sagaMiddleware = createSagaMiddleware();
  const storeMiddleware = [
    sagaMiddleware,
    reduxMiddleware.promiseCatchAll,
    thunkMiddleware.withExtraArgument(_api),
  ];

  if (process.env.NODE_ENV !== 'test') {
    storeMiddleware.push(reduxLogger);
  }

  const store = createReduxStore(
    combineReducers(reducers),
    applyMiddleware(...storeMiddleware)
  );

  sagaMiddleware.run(blockchains.sagas.root, _api);
  sagaMiddleware.run(ledger.sagas.root, _api);
  sagaMiddleware.run(addressBook.sagas.root, _api);
  sagaMiddleware.run(txhistory.sagas.root, _api);
  sagaMiddleware.run(tokens.sagas.root, _api);

redux-thunk

Thunk middleware for Redux.

MIT
Latest version published 1 year ago

Package Health Score

84 / 100
Full package analysis