[react-redux] injecting props HOC and forced exact type of OwnProps
See original GitHub issueCurrently OwnProps have to be Exact Type. Is it possible to use current connect<…> typings to create injecting-props HOC, like injectProp
example in HOC docs?
https://flow.org/en/docs/react/hoc/
function injectProp<Config: {}>(
Component: React.AbstractComponent<Config>
): React.AbstractComponent<$Diff<Config, {foo: number | void}>> {
return function WrapperComponent(
props: $Diff<Config, {foo: number | void}>,
) {
return <Component {...props} foo={42} />;
};
}
this doesn’t work and complains about OwnProps is incompatible with exact type
type Props = { ...OwnProps, foo: number };
type OwnProps = {};
const mapStateToProps = () => ({ foo: 5 });
export default connect<Props, OwnProps, _, _, _, _>(mapStateToProps);
(cc @peter-leonov)
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (12 by maintainers)
Top Results From Across the Web
React-routing v6 can't pass component props to ...
The connect HOC however is injecting the collection prop, but ownProps is simply an empty object. const mapStateToProps = (state, ownProps) ...
Read more >How to type react-redux style HOC in Typescript - Medium
So lets first type the mapProps function. This should be easy enough: We do not know the exact type of neither OwnProps nor...
Read more >Usage with TypeScript - React Redux
The package includes a helper type, ConnectedProps , that can extract the return types of mapStateToProps and mapDispatchToProps from the first ...
Read more >How to pass in an instance variable from a React component ...
I've now come up with an opinionated solution where the HoC injects two callback ... import PropTypes from 'prop-types' import movementIsStationary from '....
Read more >Building a GraphQL-powered mobile application With React
By the end of this tutorial, you'll be able to write a ... The graphql HOC injects a data prop into the decorated...
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
Maybe it’s because of my bad copy-paste skill 😃 Please, try using the code from the PR directly. It passes unit tests for types, even in Flow 0.90 😎
As far as I understood, the pre
React.AbstractComponent
type used everywhereReact.ComponentType
is now an aliastype ComponentType<T> = AbstractComponent<T, any>
. So, theoretically, it should be fine if other libraries internally used the proper types. But I’m not 100% sure.This is 100% true. I guess, Flow should allow this because (as far as I understand) it just needs the very tip of the exported type to be declared. If you get any success making it work, please, share 🤓
Quick guess: