首页 > 解决方案 > Redux saga not working after network reconnection

问题描述

Using redux saga to handle async requests. I noticed that if the user lost its network connection and execute the action, the saga will handle it on the catch block but when after while the network reconnects, sagas stop work because the function generator don't executes anymore. And just back to work again if the user refresh the page. Thats not good for ux.

I appreciate if anybody can give me a hand.

action:

export function sendMessage(room, message) {
return {
    type: 'SEND_MESSAGE',
    payload: {
        room,
        message,
    },
}}

saga:

function* sendMessage({ payload: { room, message } }) {
   yield api.sendMessage(room, message);
} catch (error) {
  /* code... */
}}

export default all([
   takeLatest('SEND_MESSAGE', sendMessage),
]);

标签: javascriptasynchronousreduxreact-reduxredux-saga

解决方案


推荐阅读