Accepted answer

Local state is fine. Even though if you are using Redux. You don't need to stop using setState() just because you're using Redux.

Redux is just a state management library in which you describe your application state as plain objects and arrays, also known as your store.

Before rendering your components, it's important to decide your state, to model your store. To help you decide if some state must be in the store (together with your whole application state), there are some questions you may ask:

  • Do other components rely on that state?
  • Do you need to persist (and/or trace) that state?

But only that doesn't answer your question (where to set initial state). If you decided to go with local state, I think your code is fine the way it is. If it needs to make part of your store, you need to set it as initial/default state for it.

You can do it in the createStore() function, passing the preloadedState argument. But if your default state is fixed (hardcoded), maybe you can put it in the initialState for dasboardReducer! Here's an example:

const initialState = {
    groupingFilter: 0,
    paginationInfo: { currentPage: 1, pageSize: 5 },
    sortInfo: ... 

function dashboardReducer(state = initialState, action) {
    // ...

What I would do in your case? I would keep all my dashboardRequest info in the store, managed by Redux. It's no a longer local state, I need to send it to the server, dispatching a side-effect action.

So, I would keep the definition of my default dashboardRequest info as my reducer's initialState, as in the example.

I really hope it helped you. Here are the readings I used for reference:

Real World examples are also welcome! Take a deep look at it: Redux Real World Example.

Good luck!

Related Query

More Query from same tag