Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine currentMentor and allMentors in the redux store #115

Open
tomduggan85 opened this issue Mar 30, 2018 · 0 comments
Open

Combine currentMentor and allMentors in the redux store #115

tomduggan85 opened this issue Mar 30, 2018 · 0 comments

Comments

@tomduggan85
Copy link

It might be simpler to keep a single list of all loaded mentors in one place in your redux store, instead of having the idea of "all mentors" and "current mentor" live in different places / reducers, to avoid having the same mentor data be duplicated in two places.

You could use allMentors as your mentor storage and then MentorPanel can look for individual mentors (the way you use currentMentor, in the mentor panel) by looking in allMentors for a specific mentorId. This lookup could happen in mapStateToProps, you could even write a selector to make this easier. Then in componentDidMount, if it doesn't find it (if currentMentor has no data), then you can kick off the network request to load that individual mentor like you currently are:

I think this will work good because if the user clicks on a card from the dashboard, then that mentor's data is already loaded when MentorPanel is being created, so you don't have to make another network request and display the "loading" content to the user for a split-second. But if that mentor is not already loaded in the store because the user opened a specific mentor's url directly, it will still load that mentor from the network.

Also, having the data live in just one place instead of being duplicated in two places will lessen the chance that they get out-of-sync as they change. For example, right now if the user updates a mentor's bio, that mentor will get updated after postField succeeds in the currentMentor reducer, but I don't think the allMentors copy of that mentor's data would get updated, so the user might return to the dashboard and see stale data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant