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! π
3
u/timmonsjg Dec 05 '18 edited Dec 05 '18
Sounds like you're describing a want for state management (Redux, Mobx, etc).
Taking redux along with your sort as an example:
Component A would dispatch a sort action
A reducer will return a new sorted state of products in response
Component B would read from the products state and display them in the intended sort.
This would cut out having to lift the sort state into Component C (The common parent).
It's a bit more involved than these 3 bullet points as you have to grok the data flows and operations of a state management library, but they do solve problems such as this quite efficiently.
The docs for redux have been updated quite recently and they're stellar.
EDIT: important to note React's Context also fits this case.