Dispatch action or action creator?
See original GitHub issueA little confused so please excuse my ignorance.
In the readme I see an example _dispatching the action_:
class UserComponent extends React.Component {
...
onSomeButtonClicked() {
const { userId, dispatch } = this.props
dispatch({type: 'USER_FETCH_REQUESTED', payload: {userId}})
}
...
}
In an example I see _dispatching of the action creator_?
import { selectReddit, invalidateReddit } from '../actions'
class App extends Component {
...
handleChange(nextReddit) {
this.props.dispatch(selectReddit(nextReddit))
}
...
}
Any reason for the variation? Don’t both approaches do the same thing?
I thought one of the benefits of sagas was the fact you no longer needed to do as much importing (hence the first example).
Trying to standardize an approach before I convert over to sagas.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Action Creators - Human Redux
It's just a utility that takes an action creator (or a whole object of action creators) and binds them all to the dispatch...
Read more >2.9 Create Action Creators For Each Action - Educative.io
These action creators are passed to the dispatch function as the result value, and the dispatch is executed.
Read more >Different Ways to Dispatch Actions with Redux - Pluralsight
Let's look at the various ways to dispatch actions with Redux. ... each function inside it is assumed to be a Redux action...
Read more >Connect: Dispatching Actions with mapDispatchToProps
Providing a mapDispatchToProps allows you to specify which actions your component might need to dispatch. It lets you provide action dispatching ...
Read more >Back to Basics: What's the Difference between an Action and ...
When writing basic Redux, an action creator simply returns an action. You would typically dispatch the action to your store immediately. store.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DarrylD thanks 😃
I think we allow to dispatch an action creator because people might want to keep using thunks with redux-saga. I think thunks are not needed anymore with redux-saga, but one might want to migrate progressively to sagas and keep both during the migration.
In this example as the selectReddit is not a thunk I don’t see much interest, except the ability to have an action builder, on which you can easily add assertions, and eventually a typesystem like typescript or flow. I’d recommend to keep the usage of actionCreators just for that as it can help maintainability.
Wether you are in a saga, or in a componnt, using an actionCreator has these advantages:
Interesting. I’m not using thunks at the moment but, I think I’ll play around some some options. I have to say, at this moment, AC’s seems pretty redundant for my use case. Maybe maintainability would be a factor but, it seems like the additional boilerplate/overhead offsets a bit.
Also gonna implement ducks, that should also help a bit.