I have a collection of articles. A user sometimes edits or deletes an article. My app keeps track in the state which article is currently being worked on (call this the currentArticleId
).
Now when a user edits or deletes an article, would I then give my action-creator the currentArticleId
as an argument (e.g.: deleteArticle(this.props.currentArticleId)
), or would I NOT do that and just fire the action creator without arguments (e.g.: deleteArticle()
), and retrieve the currentArticleId
from state in my action creator?
What's best practice here? Why would I choose one solution over the other?
If by state you mean Redux application state, then there is no right or wrong answer. You can even have two actions - deleteCurrentArticle()
or deleteArticle(articleId)
and use whatever suits you more.
However if you're asking about the component state, I think action creators should be decoupled from components. So I'd prefer passing the currentArticleId as an argument.