React Module:接受参数并导出多个值

时间:2017-04-29 06:54:40

标签: javascript reactjs

我有这样的源代码:

// createStore.js
export default (initialState = {}) => {
  const store = ...;
  return store;
}

另一个文件将被调用:

import createStore from './store/createStore';
const initialState = window.__INITIAL_STATE__;
const store = createStore(initialState);

我的问题是:我希望createStore函数可以返回true值,例如storecustomHistory,我该怎么做。

由于

2 个答案:

答案 0 :(得分:2)

返回一个对象。

return {
  store: {...},
  customHistory: {...}
}

答案 1 :(得分:0)

您可以执行以下操作:

// createStore.js
export default {
    create: (storeparam1, storeparam2, ...) => {
        // do something with your store
        store={}

    return store;
  }
}

然后在您要使用它的文件中,包含它:

// check if the file is in your current folder or not
import createStore from './createStore';

var store = createStore.create(param1, param2);