question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React-redux type for connect does not allow mapDispatchToProps as function anymore

See original GitHub issue

I’m getting the following flow error with the new react redux flow types, when using connect with a mapDispatchToProps function. The error does not occur when using an object instead.

• Either function [1] is not an object.
• Or ST [2] is not a React component.

 flow-typed/npm/react-redux_v5.x.x.js
 [2] 132│     ST: $Subtype<{[_: $Keys<Com>]: any}>

 [1]  75│ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
      76│   someProp: () => dispatch(someAction()),
      77│ });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
erictaylorcommented, Oct 16, 2018

@sherwinyu no I have not. I’ve pretty much have had to do the same thing. In some cases where we could I’ve modified mapDispatchToProps to immediately return an object, which fixes the issue, however there are lots of cases where we need the dispatch function to properly map. Would be great if someone could chime in with an appropriate fix.

5reactions
erictaylorcommented, Oct 8, 2018

@amccloud I’m having the same issue as @joshuajaco and we are using a custom Dispatch type.

type Dispatch<S = State, A = Action> = (
  action: A | ThunkAction<S, A> | PromiseAction<A>,
) => any;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect: Dispatching Actions with mapDispatchToProps
React Redux gives you two ways to let components dispatch actions: By default, a connected component receives props.dispatch and can dispatch ...
Read more >
Can't connect components with mapDispatchToProps
The mapDispatchToProps is the second argument of the connect function from the react-redux. I also think that you pass wrong the first ...
Read more >
How to deal with failure in Redux connect - Medium
But connect 's API from react-redux doesn't allow this. We can achieve this logic with an intermediary component. It can accept 2 props:....
Read more >
Defining and Using React Redux mapDispatchToProps
We use the connect function to do it. React Redux gives us 2 ways to let our components dispatch actions. We can either...
Read more >
MapStateToProps and MapDispatchToProps in React Redux
Then we throw this function inside connect and every single time when our state changes this function will be called and give us...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found