I am trying to connect a component to my Redux store using the official documentation guide, but the props connected appear to be of type never
.
Here is my code so far:
Type definitions:
export interface CardInterface {
id: string;
titulo: string;
descripcion: string;
url?: string;
fecha: Date;
}
export type CardsState = Readonly<{
cards: CardInterface[];
}>;
The actual component:
import * as React from 'react';
import { connect, ConnectedProps } from 'react-redux';
const mapStateToProps = (state: CardsState) => ({
cards: state.cards,
});
const connector = connect(mapStateToProps, null);
type Props = ConnectedProps<typeof connector>;
const CardList: React.FC<Props> = ({ cards }) => {
return (
<div className="grid-container container">
{cards.map((card: CardInterface) => (
<Card
title={card.titulo}
description={card.descripcion}
image={card.url}
/>
))}
</div>
);
};
export default connector(CardList);
When I try to iterate over the cards, the linter identifies the cards
prop as never
:
Has anyone else ran into this problem? Thank you very much.
Omitting the unused mapDispatchToProps
argument should fix this Typescript error:
const connector = connect(mapStateToProps); //instead of passing null
Apparently it's a known issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With