我正在使用Redux Promise 中间件,我的动作创建者返回一个带有承诺的动作。
现在,在 reducer 中,我收到了已解决的承诺数据,我必须“提供”新状态。我还必须对这些数据做一些不“纯粹”的事情,例如,将其存储在本地存储中。
我应该如何处理这种情况并仍然保持减速器纯净?该数据是在中间件中获得的,我第一次获得它是在减速器中。
我知道我可以在我的动作创建者中处理承诺并在分派动作之前访问数据,但是还有其他更好的方法吗?
我正在使用Redux Promise 中间件,我的动作创建者返回一个带有承诺的动作。
现在,在 reducer 中,我收到了已解决的承诺数据,我必须“提供”新状态。我还必须对这些数据做一些不“纯粹”的事情,例如,将其存储在本地存储中。
我应该如何处理这种情况并仍然保持减速器纯净?该数据是在中间件中获得的,我第一次获得它是在减速器中。
我知道我可以在我的动作创建者中处理承诺并在分派动作之前访问数据,但是还有其他更好的方法吗?
You can create your own middleware
!
You can call it localStorage-middleware
for instance and you can dispatch the action before providing your data to the reducer. Your middleware will listen to that action, like dispatch(saveDataToLocalStorage(dataToSave))