Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6347

Hooking up React Redux to a Component in Typescript

$
0
0

I am looking to hook up React Redux to my component in typescript. I am using these docs as a template.

I have the following type defining the state I have in the Redux store (there is only one):

export interface rootState {  favourites: ImageThumbnail[]}

My component:

...interface StateProps {  favourites: NasaImageThumbnail[]}interface DispatchProps {  addFavourite: () => void  removeFavourite: () => void}interface OwnProps {  ...}const mapState = (state: rootState) => ({  favourites: state.favourites})const mapDispatch = {  addFavourite: () => ({ type: 'ADD_FAVOURITE' }),  removeFavourite: () => ({ type: 'REMOVE_FAVOURITE' })}type combinedProps = StateProps & DispatchProps & OwnProps//Component bodyexport default connect<StateProps, DispatchProps, OwnProps>(  mapState,  mapDispatch)(Component)

mapState within the connect function is producing the following error:

No overload matches this call. The last overload gave the followingerror.Argument of type '(state: rootState) => { favourites: ImageThumbnail[]; }' is not assignable to parameter of type'MapStateToPropsParam<StateProps, OwnProps, DefaultRootState>'.Type '(state: rootState) => { favourites: ImageThumbnail[]; }' is not assignable to type 'MapStateToPropsFactory<StateProps,OwnProps, DefaultRootState>'.


Viewing all articles
Browse latest Browse all 6347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>