Organize large states with redux toolkit

I am fairly new to redux and redux-toolkit, but I am fairly familiar with the whole concept of stores (coming from a vuex background).

I have an issue organizing a large state with lots of dependencies between the objects. My current approach is to use a structure similar to RDBMS where each object has its own ID and other objects reference it through that ID. This way, there are no deeply nested objects.

My current problem is how to organize a large state with lots of dependencies and lots of types of objects (type of object = "table"). I could put all of the objects into a single slice, but this would make that slice incredibly large.

Another approach is to separate each of the object types into different slices, with a single slice for each object type. This presents the problem that accessing the state of another slice is not easily done but is required to update that state in order to keep the state consistent (i.e. avoid broken references).

Is there a good, common approach on how to structure a large state with a lot of dependencies?

1 answer

  • answered 2022-05-07 06:40 paulin-crtn

    Where I work we decided to go with RTK and to have one slice per entity/object related to a table in the backend (users, customers, products, etc). This is working fine.

    You can access the state of another slice by using the thunkAPI object as the second parameter of the payloadCreator callback of the createAsyncThunk function. This object contains multiple methods. One of them is getState :)

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum