- There's a page that displays a list of Posts.
- Each Post in the list links out to its individual Post page.
- Both pages contain a form to add a new Post - this is the Component.
- Additionally, the form can be shown/hidden.
The problem is that the actions need to exist in all possible Routes.
The new-post
component bubbles up to whichever Route it's being called in.
I'm calling it from the Posts Route, so I need to handle the savePost
there...
I'm also calling it from the Post Route, so I need to handle the savePost
there, as well.
Similar logic applies to the togglePostForm
action, as well.
You have two primary options if you want to DRY the action.
routes/applications.js
(which is a shared ancestor).post
route under theposts
route and thenposts
would be the shared ancestor. Here's how to do that:Depending on the situation other solutions could work, but this is a good start if you just want to have a shared action.