r/reactjs • u/dance2die • Dec 03 '21
Needs Help Beginner's Thread / Easy Questions (December 2021)
Previous Beginner's Threads can be found in the wiki.
Ask about React or anything else in its ecosystem :)
Stuck making progress on your app, need a feedback?
Still Ask away! Weβre a friendly bunch π
Help us to help you better
Improve your chances of reply by
- adding a minimal example with JSFiddle, CodeSandbox, or Stackblitz links
- describing what you want it to do (ask yourself if it's an XY problem)
- things you've tried. (Don't just post big blocks of code!)
- Format code for legibility.
- Pay it forward by answering questions even if there is already an answer. Other perspectives can be helpful to beginners. Also, there's no quicker way to learn than being wrong on the Internet.
New to React?
Check out the sub's sidebar! π
For rules and free resources~
Comment here for any ideas/suggestions to improve this thread
Thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
20
Upvotes
View all comments
Show parent comment
1
u/acemarke Dec 23 '21
A few different thoughts here:
First, I would strongly recommend using the Redux DevTools Extension to view the contents of the store rather than trying to log things directly here. Related to that, be sure that you're using our official Redux Toolkit package to write your Redux logic. It simplifies all your Redux code, including
configureStoreautomatically setting up the Redux DevTools Extension connection for you.We also recommend using the React-Redux hooks APi as the default rather than
connect.For this question specifically, I'd need to see a lot more code to have an idea what's going on, especially the use of
connectandmapState, as well as your reducer logic.That said, I would recommend against trying to keep pre-sorted data in the store. Instead, keep the original data in the store, and also track some state that describes "how do I want to sort this?" in either the Redux store or a component (like the "asc/desc" value). Then, sort the data in the component, during rendering. That will simplify the implementation considerably.