Question:
Currently, my redux store is not too organized. I have an authentication slice I created originally and wanted to add another slice for another element. I tried to have 2 separate createSlice saved in their own variable and then used combineReducer and add that to configureStore but it end up not working at all. Below is my current code that is working. As you can see the first 3 reducers is to check the state of authentication, follow by the next 2 is to check the state of a required file uploader. I couldn’t find a way to add a required prop to it. Im using filebase64 for that. The last reducer is to add the data of the post after the like button is clicked, so I can retrieve the data of the amount of likes from the state. If there is any optimized way to write these, please give me some insight.Answer:
First of all, please separate your code in different files. Creating a store in aslice
file is not following the best practices at all.From what I understood, you’re trying to create another slice so just create another file for the slice and do the same thing you have done for the
authSlice
. Then export the reducers in each slice file like this:In
authSlice.js
:store.js
file:If you have better answer, please add a comment about this, thank you!