react-redux mapStateToProps problem
See original GitHub issueHi,
don’t know if this is the right place to ask, but I’ll try anyway. Is it wrong for me to expect that flow would not report a problem in the code below? It complains on the line accessing this.props.b about ‘b’ property not being found. I would expect that because of the mapStateToProps flow would know that the b property from the state is accessible in the props. Or am I doing something wrong?
Regards, Herman
// @flow
import React, {PropTypes} from 'react'; // eslint-disable-line no-unused-vars
import {connect} from 'react-redux';
type TMyState = {
b: number
}
type Props = {
a: number;
}
class TestCase extends React.Component<void, Props, void> {
render(){
let ret = this.props.b;
return(
<div>{ret}</div>
);
}
}
function mapStateToProps(state: TMyState) {
return {
b: state.b
}
}
export default connect(mapStateToProps)(TestCase);
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Redux- mapStateToProps not working - Stack Overflow
My mistake was because I was doing wrong export/import of the component. export: export class MyComponent extends React.Component ... export ...
Read more >Connect: Extracting Data with mapStateToProps - React Redux
The first argument to a mapStateToProps function is the entire Redux store state (the same value returned by a call to store.getState() )....
Read more >MapStateToProps not being called even after changing ...
I am very new to Redux and React not sure whether this is a issue or a usage question, pls excuse my ignorance....
Read more >How to deal with failure in Redux connect - Medium
We proposed a solution based on an intermediary EitherComponent component that can fallback if we pass empty values.
Read more >How to use the react-redux.connect function in react-redux
To help you get started, we've selected a few react-redux.connect examples, ... export default connect(mapStateToProps, mapDispatchToProps)(SelectTutorial);.
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
That’s too bad there is too so much boilerplate. It would be really nice if it could infer the prototypes that come out of
connect
. All of those types already exists inStoreState
so it shouldn’t be too bad.I’m stuck behind flow v0.41 mostly because of this issue.
Our team (at Oculus, so Facebook) uses Flow and Redux, although Flow is not yet rich enough to support your use case automatically. That said, the workaround that we use is incredibly easy and very typesafe. A simplified example from our codebase for how we handle it:
Hope that helps!