r/reactjs • u/timmonsjg • Dec 03 '18
Needs Help Beginner's Thread / Easy Questions (December 2018)
Happy December! βοΈ
New month means a new thread π - November and October here.
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! Weβre a friendly bunch. No question is too simple. π€
π Want Help with your Code? π
- Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
Have a question regarding code / repository organization?
It's most likely answered within this tweet.
New to React?
π Here are great, free resources! π
38
Upvotes
View all comments
Show parent comment
1
u/soft-wear Dec 09 '18 edited Dec 09 '18
One thing to remember: how you display and how you store data don't have to be the same thing. For sorting, I'd likely use a different state object with an array of only the ids. So you
mapover the array of items but what they display is still accessible via the hash map:orderedArray.filter(id => { }).map(id => <Child score={this.state.scores[id]} />One key to remember is that the way you do things should be easy to understand, and try not to worry much about efficiency of simple data structures. None of it is going to matter because 99% of your render time is going to be the DOM API calls anyway, so any efficiency you gain from data structures are going to be all but moot relative to the dog slow DOM.
EDIT:
For clarity your state would look like:
Then you can filter in the rendered output.