React Native-异步/等待动作不会被触发

时间:2020-05-14 08:09:36

标签: react-native

我有一个动作(在其他工作方式中)没有被解雇

export const fetchJournalDB = () => {

  console.log('fetch dispatch');

  return async dispatch => {

    console.log('await');

    try {
      const dbResult = await db.listProduct();
      await dispatch({type: FETCH_JOURNAL, payload: dbResult});
    } catch (error) {
      console.log('await error', error);
    }
  };
};

如果我不使用return async dispatch,它将“正常工作”,它会显示日志,否则,我只会得到第一个日志fetch dispatch。问题出在哪儿? 谢谢

1 个答案:

答案 0 :(得分:2)

export const fetchJournalDB = () => {
return async function(dispatch){
     try{
        console.log("heyy");
        dispatch(loadinData());

     }catch{
        dispatch(fetchUsersError())

     }
 }}

只需检查一下,看来您的代码应该可以工作,但请检查该代码块中是否包含任何其他代码,