-
Notifications
You must be signed in to change notification settings - Fork 641
Don't dispatch action if action would result in no change #222
Comments
Hmm one concern I would have with this is that I believe React-Router will pass down an updated location as well (with a new key each time if you use hashhistory). You'd want the reducer to always have the same location that React-Router is passing down to its children. I guess if they were deepEqual you could avoid it, but now sure if its worth the perf hit. Maybe this is a bug/improvement on |
Not sure I follow... could you give me an example? |
Yes, this is intended. Actions don't make decisions about being dispatched. They don't even have that kind of control. Your reducer is what decides what should happen with an action (ignore it or apply it to state however it wants to). We could introduce an equality check and swallow duplicate updates. However, that would be an inconsistent behavior that would probably end up being more confusing for users ("It does this like 99% of the time!") You may even want to perform a specific action, such as a page transition, even if you're navigating to the same page. The reducer we provide can be replaced. It's not hard to extend it, since it's only 3 lines of code. That's the preferable route here. I don't think we need to change anything in the library. If anything, this belongs in |
This is also very intentional on react-router's part. If you click the same link twice in a browser, it fires events and is considered a new location (better example: click a link to the same location you are on still refreshes the page, it doesn't ignore it). |
If I'm at
/foo
and I click a link (eg on the navbar) to go to/foo
it currently dispatches an update location. Is this intended? I'd expect the action creator to check if the next location == current location & only then dispatch the action. Otherwise every time a dev writes a reducer built forUPDATE_LOCATION
he'll have to run that check himself (as is, it's a bit misleading to say UPDATE when it's technically a MAYBE_UPDATE)The text was updated successfully, but these errors were encountered: