Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress bar with redux

Tags:

reactjs

redux

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!

like image 742
Dan Avatar asked Feb 22 '16 21:02

Dan


2 Answers

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

redux devtools extension settings

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

like image 75
Kristaps Taube Avatar answered Nov 03 '22 00:11

Kristaps Taube


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.

like image 21
Dhruv Kumar Jha Avatar answered Nov 03 '22 02:11

Dhruv Kumar Jha