Using TypeScript and React/Redux, I have typed a ConnectedComponent. But when I try to render that component, TypeScript is throwing an error saying that the required props aren't passed.
Ex.
interface Props extends MapStateProps {
}
class App extends React.Component<Props, {}> {
render(): JSX.Element {
return (
<>
<Router>
<Switch>
<Route path="/" component={Dashboard} />
</Switch>
</Router>
</>
);
}
}
interface MapStateProps {
user: UserState;
}
const MapStateToProps = (state: AppState): MapStateProps => ({
user: state.user,
});
const connectedApp = connect(MapStateToProps, null)(App);
export {
connectedApp as App,
};
Then when I render the component like:
<App />
It says that App requires the 'user' prop. How can I do this without setting the user prop as optional?