Skip to content

fix(docs): remove mapDispatchToProps invalid use case #1364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2019
Merged

fix(docs): remove mapDispatchToProps invalid use case #1364

merged 1 commit into from
Jul 26, 2019

Conversation

unrevised6419
Copy link

Tried every form of mapDispatchToProps
dispatch is never missing from props

@netlify
Copy link

netlify bot commented Jul 26, 2019

Deploy preview for react-redux-docs ready!

Built with commit dc2c1b8

https://deploy-preview-1364--react-redux-docs.netlify.com

Tried every form of `mapDispatchToProps`
`dispatch` is never missing from `props`
@unrevised6419 unrevised6419 changed the title fix(docs): remove mapDispatchToProps untruthy use case fix(docs): remove mapDispatchToProps untruthy use case Jul 26, 2019
@timdorr timdorr changed the title fix(docs): remove mapDispatchToProps untruthy use case fix(docs): remove mapDispatchToProps invalid use case Jul 26, 2019
@timdorr
Copy link
Member

timdorr commented Jul 26, 2019

Yep, that's out of date. Thanks!

@timdorr timdorr merged commit ae6f033 into reduxjs:master Jul 26, 2019
@unrevised6419 unrevised6419 deleted the patch-1 branch July 26, 2019 18:22
@markerikson
Copy link
Contributor

Uh.... wait, what? No, we don't pass dispatch in if you do mapDispatch. We never have.

@markerikson
Copy link
Contributor

See the current implementation here:

export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
return typeof mapDispatchToProps === 'function'
? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps')
: undefined
}
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
return !mapDispatchToProps
? wrapMapToPropsConstant(dispatch => ({ dispatch }))
: undefined
}
export function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
return mapDispatchToProps && typeof mapDispatchToProps === 'object'
? wrapMapToPropsConstant(dispatch =>
bindActionCreators(mapDispatchToProps, dispatch)
)
: undefined
}

We return the result of mapDispatch(dispatch) if it's a function, the result of bindActionCreators(mapDispatch, dispatch) if it's an object, and () => {dispatch} if it's missing.

The existing docs were correct. Reverting.

@unrevised6419
Copy link
Author

unrevised6419 commented Jul 26, 2019

Hmm, my bad, it seems another HOC is injecting dispatch.
https://codesandbox.io/s/awesome-thompson-l45q2

@timdorr
Copy link
Member

timdorr commented Jul 27, 2019

Whoops, my bad for merging without thinking too hard!

albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
Tried every form of `mapDispatchToProps`
`dispatch` is never missing from `props`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants