Progress bar with redux

一笑奈何 提交于 2020-01-02 00:50:31

问题


I have a background upload process in my react/redux application that updates very frequently. My reducer looks something like this:

export default function progressReducer(state = initialState, action = {}) {
  switch (action.type) {
    case PROGRESS_TOTAL_INCREASE:
      return Object.assign({}, state, {total: state.total + action.amount});
    case PROGRESS_CURRENT_INCREASE:
      let current = state.current + action.amount, total = state.total;
      if (current >= state.total && false) {
        state.total = 0;
        current = 0;
      }
      return {total, current};
    default:
      return state;
  }
}

It works. Great. But the redux devtool log fills up very quickly with progress actions, drowning out any other actions. Is this the right approach, or should I be looking at a different way of creating these notifications?

Thanks!


回答1:


If you are using redux devtools chrome extension, you can just list action that should be hidden in extensions settings.

Otherwise, if you have integrated it in your project, checkout redux-devtools-filter-actions monitor.




回答2:


I will start by saying use your common sense, Most of the time it will make the right decision.

Here's what i suggest

  • If multiple components need to keep track of the upload progress, Its best to use redux.

  • If only a specific component needs to keep track of upload progress, You can just update that components state.

    Do remember if you're using components state, you can no longer make use of Pure functional components... as they don't have state

  • If you want to use redux but want to keep the store updates minimum, you can just dispatch action when the upload starts and when its completed, and based on this you can render a loading bar.. so visually user will know upload is in progress.



来源:https://stackoverflow.com/questions/35563846/progress-bar-with-redux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!