• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to make 2 createSlice with redux?

Resolved: How to make 2 createSlice with redux?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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 a slice 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:
In the other slice file:
Then import them in the store.js file:

If you have better answer, please add a comment about this, thank you!

react-redux reactjs redux redux-store
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Resolved: VBA – Applying border around the areas with value/text

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.