Javascript Redux thunk:`分派不是一个函数`

Javascript Redux thunk:`分派不是一个函数`,javascript,redux,redux-thunk,apollo,Javascript,Redux,Redux Thunk,Apollo,因此,我遇到了一个问题,一个操作返回上述错误(见附件),而不是像预期的那样更新redux状态。我在这里俯瞰什么 actionCreators.js export function userToken(token) { console.log('userToken has been fired'); return (dispatch) => { dispatch({ type: 'Graphcool_Token', payload: token

因此,我遇到了一个问题,一个操作返回上述错误(见附件),而不是像预期的那样更新redux状态。我在这里俯瞰什么

actionCreators.js

export function userToken(token) {
  console.log('userToken has been fired');
  return (dispatch) => {
    dispatch({
      type: 'Graphcool_Token',
      payload: token
    });
  } 
}
....
// Root Query
const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, {
  options: {
    cachePolicy: 'offline-critical', 
    fetchPolicy: 'cache-first',
  },
});

export const mapDispatchToProps = (dispatch) => {
  return bindActionCreators(actionCreators, dispatch);
}

export default compose(
  allPostsCommentsQuery,
  connect(mapDispatchToProps)
)(Main);
  signinUser: function(emailID, passwordID) {

    const email = emailID;
    const password = passwordID;

    this.props.client.mutate({
      mutation: signinUser_Mutation,
      variables: {
        email,
        password,
      },
      options: {
        cachePolicy: 'offline-critical', 
        fetchPolicy: 'cache-first',
      },
    })
    .then(this.updateStateLoginDetails)
    .catch(this.handleSubmitError);
  },

  updateStateLoginDetails: function({data}) {
    this.props.userToken(data.signinUser.token);
  },
App.js

export function userToken(token) {
  console.log('userToken has been fired');
  return (dispatch) => {
    dispatch({
      type: 'Graphcool_Token',
      payload: token
    });
  } 
}
....
// Root Query
const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, {
  options: {
    cachePolicy: 'offline-critical', 
    fetchPolicy: 'cache-first',
  },
});

export const mapDispatchToProps = (dispatch) => {
  return bindActionCreators(actionCreators, dispatch);
}

export default compose(
  allPostsCommentsQuery,
  connect(mapDispatchToProps)
)(Main);
  signinUser: function(emailID, passwordID) {

    const email = emailID;
    const password = passwordID;

    this.props.client.mutate({
      mutation: signinUser_Mutation,
      variables: {
        email,
        password,
      },
      options: {
        cachePolicy: 'offline-critical', 
        fetchPolicy: 'cache-first',
      },
    })
    .then(this.updateStateLoginDetails)
    .catch(this.handleSubmitError);
  },

  updateStateLoginDetails: function({data}) {
    this.props.userToken(data.signinUser.token);
  },
减速器

var tokenDetails = function(state, action) {

  if (state === undefined) {
    state = [];
  }

  switch (action.type) {
    case 'Graphcool_Token':
      const newState = [action.payload];
      return newState;
    default:
      return state;
  }
}

export default tokenDetails;
logiuser.js

export function userToken(token) {
  console.log('userToken has been fired');
  return (dispatch) => {
    dispatch({
      type: 'Graphcool_Token',
      payload: token
    });
  } 
}
....
// Root Query
const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, {
  options: {
    cachePolicy: 'offline-critical', 
    fetchPolicy: 'cache-first',
  },
});

export const mapDispatchToProps = (dispatch) => {
  return bindActionCreators(actionCreators, dispatch);
}

export default compose(
  allPostsCommentsQuery,
  connect(mapDispatchToProps)
)(Main);
  signinUser: function(emailID, passwordID) {

    const email = emailID;
    const password = passwordID;

    this.props.client.mutate({
      mutation: signinUser_Mutation,
      variables: {
        email,
        password,
      },
      options: {
        cachePolicy: 'offline-critical', 
        fetchPolicy: 'cache-first',
      },
    })
    .then(this.updateStateLoginDetails)
    .catch(this.handleSubmitError);
  },

  updateStateLoginDetails: function({data}) {
    this.props.userToken(data.signinUser.token);
  },
store.js

从'redux'导入{createStore,applyMiddleware,compose};
从“redux persist”导入{persistStore,autoRehydrate};
从“react router redux”导入{syncHistoryWithStore};
从“react router”导入{browserHistory}
从“redux thunk”导入thunk;
从“./reducers/index”导入rootReducer;
从“/apolloClient”导入客户端;
从“localfollow”导入localfollow;
const middleware=[thunk,client.middleware()];
常量增强子=合成(
applyMiddleware(…中间件),
(窗口类型.uuu REDUX_DEVTOOLS_EXTENSION_uu!='undefined'| process.env.NODE_env!=='production')?窗口.uuuu REDUX_DEVTOOLS_EXTENSION:(f)=>f,
自动脱水(),
);
const store=createStore(
减根剂,
{},//初始状态
增强剂
);
//开始定期持久化存储
persistStore(store,{storage:localfollow});
export const history=syncHistoryWithStore(
浏览历史,
百货商店
);
如果(模块热){
module.hot.accept(“./reducers/”,()=>{
const nextrotreducer=require('./减缩器/索引')。默认值;
储存、更换减速器(下一个减速器);
});
}

导出默认存储
应该传递给
connect
的第一个参数是
mapstatetops
,它是一个接收
状态和组件
道具的函数。。如果不需要,您应该在那里添加
null

connect(空,mapDispatchToProps)(主)

顺便说一句,一般来说,您不需要
bindActionCreators
。。通常返回一个对象就足够了,比如:

const mapDispatchToProps = {
  someActionName,
  someOtherAction,
}

您应该传递给
connect
的第一个参数是
mapstatetops
,它是一个接收
状态和组件
道具的函数。。如果不需要,您应该在那里添加
null

connect(空,mapDispatchToProps)(主)

顺便说一句,一般来说,您不需要
bindActionCreators
。。通常返回一个对象就足够了,比如:

const mapDispatchToProps = {
  someActionName,
  someOtherAction,
}

你能展示一下你是如何创建/配置Store的吗?你在导入你的actions和BindActionCreator吗?即从“redux”导入{bindActionCreators}
从“../actions/actionCreators”导入{actionCreators}
connect(mapDispatchToProps)
:mapDispatchToProps
不是
connect
的第二个参数吗?@PriyeshKumarI已更新我的问题以显示我的存储。@Davintroon正确。唯一的区别是我正在做,
import*作为“../actions/actionCreators”的actionCreators能否显示如何创建/配置Store?是否导入操作和BindActionCreator?即从“redux”导入{bindActionCreators}
从“../actions/actionCreators”导入{actionCreators}
connect(mapDispatchToProps)
:mapDispatchToProps
不是
connect
的第二个参数吗?@PriyeshKumarI已更新我的问题以显示我的存储。@Davintroon正确。唯一的区别是我正在做,
import*作为“../actions/actionCreators”的actionCreators您的信息为我解决了问题。非常感谢。@enapupe谢谢你!你的信息为我解决了这个问题。非常感谢。@enapupe谢谢你!