Skip to content

Instantly share code, notes, and snippets.

@seanwash
Last active October 12, 2016 01:08
Show Gist options
  • Select an option

  • Save seanwash/c0029aaabdf8ea808e54878cd8b161a8 to your computer and use it in GitHub Desktop.

Select an option

Save seanwash/c0029aaabdf8ea808e54878cd8b161a8 to your computer and use it in GitHub Desktop.
React/Redux/Router Flow

So, right now I have a landing page that fetches all of my data through an action.

When the user clicks to view a singular item from the landing page (items -> items/:id), should the page component dispatch an action called findItemByID, the reducer do the finding and set a {currentItem: id} object on the root store? You'd essentially have something like:

  items: { "items": [], "currentItem": 10, "fetching": false, "fetched": true, "errors": null }

How do you handle this flow in Redux? Am I doing it all wrong?

@seanwash

Copy link
Copy Markdown
Author

Or, I could also use some local state on the singular item component container where on mount it gets the id from the router and then uses lodash to do something like _.find(this.props.items, (item) => {item.id === currentID}) and set the result to this.state.item. Local state isn't a bad thing, right?

@Snazzyham

Copy link
Copy Markdown

I'm not really that clear on how Redux works, but I'm learning it at university at the moment and one thing my tutor stressed on is that if you're using Redux, you always want it to be passed in as props and never use local state.

@seanwash

seanwash commented Oct 12, 2016

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment